ImagePipe.Source.CachePolicy (image_pipe v0.1.0)

Copy Markdown View Source

Cache storage and freshness policy for originals and processed images.

ImagePipe.config(
  source_cache_policy: [storage: :origin, freshness: {:fallback, 300}],
  sources: [...]
)

:source_cache_policy in ImagePipe.config/1 sets the policy for every source. A source's own :cache_policy replaces it field by field. All durations are in seconds. See source cache settings and caching and freshness.

An immutable source has no freshness deadline, even when it inherits a finite :freshness, but still needs :storage to allow storing. Its own :cache_policy can't set a :freshness duration or a :stale_while_revalidate window.

Options

  • :storage (:origin, :allow, or :deny) - Whether originals and processed images may be stored. :origin, the default, stores unless the origin sends no-store or private. :allow stores despite them, and :deny never stores. Vary: * from the origin prevents storage in every mode.

  • :freshness (:origin, {:fallback, seconds}, or {:force, seconds}) - How long a stored copy stays fresh. :origin, the default, uses the origin's lifetime and revalidates on every request when there is none. {:fallback, seconds} applies only when the origin sends no lifetime. {:force, seconds} replaces the origin's lifetime, including no-cache. Neither makes a response storable that :storage doesn't allow.

  • :stale_while_revalidate (:origin, :disabled, or {:force, seconds}) - How long an expired copy may still be served while it is refreshed. :origin, the default, uses the origin's stale-while-revalidate, which an origin no-cache, must-revalidate, proxy-revalidate, or s-maxage turns off. :disabled serves no expired copies. {:force, seconds} sets the window, whatever the origin sends.

Summary

Functions

Merges validated policies field by field, with source settings taking precedence.

Types

t()

@type t() :: keyword()

Functions

merge(defaults, overrides)

@spec merge(t(), t()) :: t()

Merges validated policies field by field, with source settings taking precedence.

validate(opts)

@spec validate(term()) :: {:ok, t()} | {:error, String.t()}