CacheMoney (Cache Money v0.6.2) View Source
Handles caching values under different cache names, can expire keys
Link to this section Summary
Types
The name of the cache, used for namespacing multiple caches on the same adapter. Can be either a binary or an atom, but will always be converted to a binary.
The key a value will be set under. Can be either a binary or an atom, but will always be converted to a binary.
Currently the only option available is an optional timeout
that gets passed
along with GenServer.call
The value to be saved in the cache. Can be any value going in to the cache,
but depending on the adapter used, may not be the same value going out. For
example, CacheMoney.Adapters.ETS
can save any elixir term, including pid
s.
CacheMoney.Adapters.Redis
, however, can only save items as strings.
Functions
Returns a specification to start this module under a supervisor.
Deletes the key
from the cache
Gets the value out of the cache using the key
.
Gets the value out of the cache using the key
. Lazily fetches the data, inserts
it into the cache, and returns it if it does not exist. Optional expiry
is in
seconds.
Sets key
in the cache to value
Sets key
in the cache to value
Sets key
in the cache to value
, which expires after expiry
seconds
Starts a CacheMoney
process linked to the current process.
Link to this section Types
Specs
The name of the cache, used for namespacing multiple caches on the same adapter. Can be either a binary or an atom, but will always be converted to a binary.
Specs
The key a value will be set under. Can be either a binary or an atom, but will always be converted to a binary.
Specs
Specs
options() :: [{:timeout, integer()}]
Currently the only option available is an optional timeout
that gets passed
along with GenServer.call
Specs
server() :: GenServer.server()
Specs
value() :: term()
The value to be saved in the cache. Can be any value going in to the cache,
but depending on the adapter used, may not be the same value going out. For
example, CacheMoney.Adapters.ETS
can save any elixir term, including pid
s.
CacheMoney.Adapters.Redis
, however, can only save items as strings.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
Deletes the key
from the cache
Specs
Gets the value out of the cache using the key
.
If the value does not exist in the cache nil
will be returned.
Specs
get_lazy(server(), key(), lazy_function(), integer() | nil, options()) :: {:ok, value()} | {:error, any()}
Gets the value out of the cache using the key
. Lazily fetches the data, inserts
it into the cache, and returns it if it does not exist. Optional expiry
is in
seconds.
Specs
Sets key
in the cache to value
Specs
Sets key
in the cache to value
Specs
Sets key
in the cache to value
, which expires after expiry
seconds
Specs
start_link(cache_name(), map(), Keyword.t()) :: GenServer.on_start()
Starts a CacheMoney
process linked to the current process.
Arguments
- cache - the name of the cache. Multiple caches using the same adapter will all be in the same spot, but will be namespaced by the given cache name.
- conifg - contains various configuration options for the cache, depending on
the adapter.
:adapter
is required to be set, and must be set to a module that implementsCacheMoney.Adapter
, such asCacheMoney.Adapters.Redis
orCacheMoney.Adapters.ETS
. Different adapters will also specify other required optionso be passed to them through theconfig
argument - opts - see
GenServer.start_link/3
. Options are passed straight through to the underlyingGenServer