{#========================================== Spincast HTTP Caching plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins plugins-spincast-http-caching{% endblock %} {% block meta_title %}Plugins - Spincast HTTP Caching{% endblock %} {% block meta_description %}Spincast HTTP Caching plugin : ETag, Cache-Control, etc.{% endblock %} {% block scripts %} {% endblock %} {% block body %}
The Spincast HTTP Caching plugin provides utilities to
send and validate cache headers. The main component is the
request context add-on, ICacheHeadersRequestContextAddon.
For the full documentation about HTTP caching using Spincast, please have a look at the HTTP caching section.
If you use the spincast-default artifact, this plugin is already installed so
you have nothing more to do!
If you start from scratch using the spincast-core artifact, you can use the
plugin by adding this artifact to your project:
<dependency>
<groupId>org.spincast</groupId>
<artifactId>spincast-plugins-http-caching</artifactId>
<version>{{spincastCurrrentVersion}}</version>
</dependency>
You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
Injector guice = Guice.createInjector(
new SpincastCoreGuiceModule(args),
new SpincastHttpCachingPluginGuiceModule(IAppRequestContext.class,
IAppWebsocketContext.class)
// other modules...
);
... or by using the install(...) method from your custom Guice module:
public class AppModule extends SpincastCoreGuiceModule {
@Override
protected void configure() {
super.configure();
install(new SpincastHttpCachingPluginGuiceModule(getRequestContextType(),
getWebsocketContextType()));
// other modules...
}
// ...
}
public void myHandler(IAppRequestContext context) {
// Sends "Cache-Control" header
context.cacheHeaders().cache(60);
// Validates the "freshness" headers
if(context.cacheHeaders().eTag(etag).lastModified(date).validate(true)) {
return;
}
}
ICacheHeadersRequestContextAddon<R> eTag(String currentTag)
A strong comparison will be used to compare the request ETag to this current ETag.
Skip, or use null if the resource doesn't exist.
ICacheHeadersRequestContextAddon<R> eTag(String currentTag, boolean currentTagIsWeak)
A strong comparison will be used to compare the request ETag to this current ETag.
Skip, or use null if the resource doesn't exist.
ICacheHeadersRequestContextAddon<R> eTag(String currentTag, boolean currentTagIsWeak, boolean weakComparison)
Skip, or use null if the resource doesn't exist.
ICacheHeadersRequestContextAddon<R> lastModified(Date lastModificationDate)
Skip, or use null if the resource doesn't exist.
ICacheHeadersRequestContextAddon<R> cache(int seconds)
ICacheHeadersRequestContextAddon<R> cache(int seconds, boolean isPrivate)
ICacheHeadersRequestContextAddon<R> cache(int seconds, boolean isPrivate, Integer secondsCdn)
ICacheHeadersRequestContextAddon<R> noCache()
boolean validate(boolean resourceCurrentlyExists)
ETag and/or Last-Modified to validate
them agains the headers sent by the client.
If this method returns true, the route handler should return immediately
without returning/creating/modifying/deleting the associated resource! Appropriate headers
have already been set on the response.