Cache.PersistentTerm (elixir_cache v0.5.0)

Copy Markdown View Source

:persistent_term adapter for storing rarely-written, frequently-read cached values.

This adapter stores values in Erlang's :persistent_term storage, which provides extremely fast read access at the cost of more expensive writes and deletes. It is best suited for configuration values or other data that changes infrequently.

TTL is not supported — values persist until explicitly deleted.

Example

defmodule MyApp.Cache do
  use Cache,
    adapter: Cache.PersistentTerm,
    name: :my_app_persistent_cache,
    opts: []
end

Summary

Functions

Returns a specification to start this module under a supervisor.

:persistent_term exists to hand out zero-copy references to already-built terms. Encoding a value into a binary and decoding it on every read defeats the entire point of the adapter, so it never encodes.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

arg is passed as the argument to Task.start_link/1 in the :start field of the spec.

For more information, see the Supervisor module, the Supervisor.child_spec/2 function and the Supervisor.child_spec/0 type.

native_term_storage?(opts)

:persistent_term exists to hand out zero-copy references to already-built terms. Encoding a value into a binary and decoding it on every read defeats the entire point of the adapter, so it never encodes.