OHGO

Caching

What are the cache headers?

Every resource can define its own caching policy via http headers.

Most browsers are designed to take advantage of these values to reduce unessesary trips to the server.

            Cache-Control: public, max-age=64
            Age: 52
            Date: Thu, 21 Feb 2019 22:15:52 GMT
            Expires: Thu, 21 Feb 2019 22:16:05 GMT
            Last-Modified: Thu, 21 Feb 2019 22:15:00 GMT
            ETag: "20190221101605"
        

Headers

  • Cache-Control: Directives control who caches the response, under what conditions and for how long.
    • Public/Private:
    • Max-Age: Maximum number of seconds a response may be cached.
  • Age: Current age of the cached data in seconds.
  • Date: Date of the response.
  • Expires: Date the cache for this result ends.
  • Last-Modified: Date the cache was generated.
  • ETag: Unique value used to check for new or updated data.(See below)

What is an ETag?

Using ETags you may check to see if the data has changed from the previous request and receive a 304 status code if the data is the same.

The reason to do this is to prevent downloading and refreshing of your client data when it is not needed.

This saves on bandwidth usage and time.

How to set an ETag?

Send a valid request to one of the endpoints will return headers with an ETag value.

            ETag: "20190221101605"
        

On the next request send Header

            If-None-Match: 20190221101605
        

If the data has changed since the last request, you will receive a 200 status code along with the requested data.

If the data has NOT changed since the last request, you will receive a 304 status code and no data.