ShieldedCache v1.2.2 ShieldedCache behaviour View Source

ShieldedCache

ShieldedCache is a caching module for Elixir.

What makes it special?

It enables a type of CDN Shielding on your cache that allows you to return stale results while simultaneously refreshing your data. This allows you to always return data to your client incredibly fast after the first request is made, while still refreshing data in an async way to keep subsequent requests fresh.

Callbacks

  • fetch/1: Executes the cache request and fetches the data
  • key/1: Generates a key out of the cache request

Overrideable Functions

  • key/1: Generates a key from a cache request
  • pre_get_side_effect/1: Creates a side effect before the get happens in the cache
  • post_get_side_effect/1: Creates a side effect after the get happens in the cache
  • pre_fetch_side_effect/1: Creates a side effect before the fetch happens in the cache
  • post_fetch_side_effect/1: Creates a side effect after the fetch happens in the cache
  • expired_side_effect/1: Creates a side effect when an expired value is returned from the cache
  • first_fetch_side_effect/1: Creates a side effect on the first fetch of the request (when there is no previous value for this request in the cache)
  • get_or_fetch_response_time_side_effect/2: Creates a side effect with the response time of the get_or_fetch function for the request
  • get_response_time_side_effect/2: Creates a side effect with the response time of the get function for the request
  • fetch_response_time_side_effect/2: Creates a side effect with the response time of the fetch function for the request

Defaults

  • key/1: Uses the serialize!/1 function to serialize whatever the cache request is into a key for the cache.
  • pre_get_side_effect/1: Does nil
  • post_get_side_effect/1: Does nil
  • pre_fetch_side_effect/1: Does nil
  • post_fetch_side_effect/1: Does nil
  • expired_side_effect/1: Does nil
  • first_fetch_side_effect/1: Does nil
  • get_or_fetch_response_time_side_effect/2: Does nil
  • get_response_time_side_effect/2: Does nil
  • fetch_response_time_side_effect/2: Does nil

Link to this section Summary

Types

Return values of all functions for the cache

Link to this section Types

Link to this type fetch_return() View Source
fetch_return() :: {:ok, value :: any()} | {:error, reason :: any()}

Return values of all functions for the cache

Link to this section Functions

Link to this function initialize_configuration(opts) View Source
initialize_configuration(opts :: Keyword.t()) ::
  {cache_name :: module(), caching_module :: module(), opts :: Keyword.t()}
Link to this function verify_caching_module(module) View Source
verify_caching_module(module :: module()) :: module :: module()

Link to this section Callbacks

Link to this callback fetch(cache_request) View Source
fetch(cache_request :: term()) :: fetch_return()
Link to this callback key(cache_request) View Source
key(cache_request :: any()) :: key :: String.t()