Etags / Cache headers / No cache / Cache busting

2016-07-30 9:00 PM (3 years ago)

You can guess it from the title : this new release is all about HTTP Caching! HTTP Caching is a fundamental part of any web framework and was obviously a required step before Spincast 1.0.0.

Many frameworks only manage a very little part of the HTTP specification regarding caching. In general, they limit their support to GET requests by returning a 304 - Not Modified response instead of the requested resource if this resource hasn't changed, and they validate this by hashing the generated resource and setting the result as an ETag header. This is useful in some cases, but is in fact very limited... HTTP caching is way more sophisticated than this!

At the core of HTTP Caching management using Spincast, there is a new request context add-on : "httpHeaders()". This add-on helps to create very compliant REST endpoints. Most of the "freshness" headers are managed : If-Match, If-None-Match, If-Modified-Since and If-Unmodified-Since. In the other direction, the add-on helps to send Cache-Control, ETag and Last-Modified headers. It is also possible to send "no cache" headers to tell a client that it should never cache the resource, at all. Some of those cache headers can also be specified on the routes, directly.

Finally, a Cache Busting mechanism has been added. By adding a special code to the URL of a resource, you can easily invalidate the cached versions clients may have of it. Read more about it here.