This module add the ability to control the caching of your tapestry pages by simply annotating the page class.
@CacheControl(cacheType = CacheType.NEVER)
public class myPage(){
....
}
This library supports the following cachetypes
The cache types are configured via application defaults so you can override them by contributing your own preferences. The time parameter is in seconds.
public static void contributeApplicationDefaults(MappedConfiguration<String,String> configuration)
{
configuration.add(cacheControl.short, "60");
configuration.add(cacheControl.medium, "600");
configuration.add(cacheControl.long, "6000");
configuration.add(cacheControl.farFuture, "60000");
}
The library also has a default cache header applied to all pages. This default is set (by default) to NONE which does nothing. This can also be changed by contributing a default
e.g. changing it to NEVER would require the following
configuration.add("cacheControl.default", CacheType.NEVER.name());
It is possible to set and use cache control headers on AJAX events. This can be very handy as they can cause substantial load. However this also comes with a health warning - you need to think carefully before enabling this as if you do it wrong you could share data between users!
You need to enable this by add the following application default
configuration.add("cacheControl.enableEventHeaders", String.valueOf(true));
This will enable setting cache control headers for AJAX events. This will change all tapestry AJAX events to use a GET instead of a post.
The headers set will be
public Block onActionFromNoneAjax() {
cacheControlSupport.setCacheType(CacheType.NONE);
return ajaxResponse;
}
The library seeks to use headers that will work with many proxy servers/browsers so it sets
The ajax event implementation overides the ajaxRequest function is tapestry.js to change the default method to GET (as opposed to POST). This is a global setting so once enabled will impact ALL ajax requests.
This is done as part of page initialisation - it is not therefore guarenteed if you called Tapestry.ajaxRequest in an included JS file it will run after (or before) this overide occurs. In reality this is unlikely to be an issue as AJAX doesn't generally occur on page load - and if you wanted to do that putting your call in an init function should solve the issue.