wcomp-logo WebComp



  home  print

Support for caching of generated pages

Much can be gained in better performance and less server load, if a web-application has proper support for web caching. WebComp can respond properly to revalidation requests and generate responses using the 'cache-control' header, to support caches placed between client and the server.

Revalidation and 'is-modified-since'

Clients and web-caches can send GET requests with the 'is-modified-since' header set to the time the given document was last served. If the server finds that the document was not modified since the given time it may respond with a empty response saying that the cached copy is still valid.

All components should implement the method lastModified, which are consulted every time a validation request is received. Since a WebComp generated page is composed by many components, the latest time found among the parts, will be used. Components may also return 0 which means that the time should be set to the current time. Components representing static files will use the file's last modified time and components defined from the script will use the time the script was last modified or the time the server was restarted.

Time to live

WebComp can indicate to caches or clients if or how long to cache the generated pages, by using the 'cache-control' response header.

The Time To Live value is returned, using the 'cache-control' header ('max-age' subheader).This reflects the number of seconds to consider a response fresh, before doing revalidation. In scripts, one may define the value to be used by default by defining the global attribute 'DEFAULT_TTL'. Components may override this value. WebComp also provide a special function (TTL) to explicitly override the default ttl value in scripts. If the ttl value is set to 0, the 'cache-control' response header will say: 'no-cache' to indicate that the document should not be cached at all.

The example shows how to define a default value of 1 hour (which is used for the first menu item, and a explicitly overridden value of 10 minutes for the second menu item.

DEFAULT_TTL = 36000;
start:  "First page"  -> firstpage.html;
second: "Second page" -> $ttl | 600 | secondpage.html;