httpSetMaxAge()

Defines the time in seconds how long files should be cached by the client.

Synopsis

int httpSetMaxAge( uint maxAge);

Parameter

Parameter Description
maxAge Time in seconds how long files are cached by the client.

Return value

httpSetMaxAge() returns 0 on success, otherwise -1.

Error

Errors can be queried with getLastError(). Errors can be:

  • Too few arguments

  • No httpServer() is installed

  • httpSetMaxAge() is called from a different script than the httpServer() was installed from

  • The given web resource is not registered

Description

The function httpSetMaxAge() defines the time in seconds how long files should be cached by the client, i.e. the maximum cache time (Response Header Cache Control and Expires). From this value the Cache Control (equals to maxAge) as well as Expires (current time + maxAge) is calculated.

This function is meaningful when the client must request the same files from the server several times.

Example

#uses "CtrlHTTP"
main()
{
  httpServer();// Installs the HTTP server
  httpSetMaxAge(3600); // Files are cached 1 hour
  httpConnect("example", "/firstExample");
}
string example()
{
  return "<html><head><title>First
  Example</title></head>"
  "<body>This is my first HTML
  example</body></html>";
}

Assignment

CTRL PlugIn

Availability

CTRL