Details On JGate's New Caching Layer
With the latest change, we added Varnish as a caching reverse proxy. Varnish is often called a "HTTP Accelerator", and it indeed gave our site a huge speed boost.
As soon as the caching layer was activated in week 34, the simultaneous connections to the back-end were reduced by more than 50% and the load was lowered significantly.
Varnish uses numerous techniques to improve the performance. It even has compiled configuration libraries, in-memory logging, and works hand in hand with the OS for memory management.
Cache Invalidation
Recently several sites (for instance Heroku and Posterous) reported the introduction of Varnish, but all have chosen a different cache strategy. The biggest challenge when using caching is the control of the cache TTL and cache invalidation. Varnish has built-in support to control caching, but this requires a lot of work and is specific to Varnish. Posterous has done a more generic, very interesting ajax-based approach.
We use a more traditional way using parameter control. Varnish only delivers a cached page, when it is absolutely safe to do so. The URL and all parameters have to match for a cache hit. So the backend can control caching by adding a synthetic parameter to every request, that we call a cache token.
To explain this, here is an example: The response to the "list applications" Ajax call is cached for a hour. Without cache control a deleted application, for example, would still be listed for a hour. The trick here is to issue a new cache token with such an operation. Varnish sees a parameter difference and delivers a fresh response from the back-end in return.
Cache TTL Control
Every application that is hosted on JGate, even when running on a custom domain, leverages the caching layer. The time to live, or TTL, can easily be controlled using AppJets response.setCacheable() call. By default, pages are not cached. When set to true, pages are cached for a long time, a perfect choice for pictures and other static content. When set to undefined, the cache headers need to be supplied by the application. This option allows custom control of the cache.