OgEx.ResourceCache (og_ex v0.2.0)

Copy Markdown View Source

Bounded in-memory cache for verified remote resources.

Entries retain encoded bytes, fingerprints, and HTTP validators. Fresh entries are returned directly; stale entries are available only for conditional revalidation. The table is local to one BEAM node.

Summary

Functions

Returns a specification to start this module under a supervisor.

Fetches a non-expired cached resource.

Returns a cached resource even after its freshness TTL has elapsed.

Inserts one cache entry and clears the cache before it can exceed its bounds.

Creates the private ETS table used by the cache.

Stores a resource for ttl milliseconds while enforcing configured bounds.

Starts the process that owns the resource ETS table.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fetch(key)

Fetches a non-expired cached resource.

Returns {:ok, resource} or :error, following Map.fetch/2.

fetch_stale(key)

Returns a cached resource even after its freshness TTL has elapsed.

The remote loader uses stale entries only to send conditional validators or to reuse bytes after a 304 Not Modified response.

handle_call(msg, from, state)

Inserts one cache entry and clears the cache before it can exceed its bounds.

init(options)

Creates the private ETS table used by the cache.

put(key, resource, ttl)

Stores a resource for ttl milliseconds while enforcing configured bounds.

The default bounds are 128 entries and 25,000,000 bytes. When an insertion would exceed either bound, the current table is cleared first.

start_link(options \\ [])

Starts the process that owns the resource ETS table.