ex_no_cache v0.1.0 ExNoCache.Plug.Content View Source

A plug for caching a mid to long term dynamic content.

Requires one option:

Cache mechanisms

ExNoCache.Plug.Content uses etag for HTTP caching. This means a client should cache the response on the first request and validate the cache on following requests. The cache-control for etag uses "private" mode meaning that the content will be kept in the client browser only.

ExNoCache.Plug.Content generate etag using sha256 digest from the response body upon running. It stores the generated etag in ExNoCache.Cache.GenServer as a map of request path and etag.

Usage

Using ExNoCache.Plug.Content is very simple, just plug it into any GET request path you want to cache and be done with it.

Please be aware that the ExNoCache.Plug.Content works only with GET method. It should be used only with a static path that can generate a dynamic content but the content is rarely change.

ExNoCache.Plug.Content should be used as a last resort only when you cannot determined the last updated time of the content. Otherwise use ExNoCache.Plug.LastModified should be better in terms of efficiency since ExNoCache.Plug.Content always allows the request to be processed first before determining the cache-control strategy.

Examples

This plug can be mounted in a Plug.Builder pipeline as follows:

def MyPlug do
  use Plug.Builder

  plug ExNoCache.Plug.Content, store: ExNoCache.Cache.GenServer
end

Link to this section Summary

Link to this section Types

Specs

options() :: [{:store, module()}]