Box.Cache (box v0.15.1)
View SourceCache related function. They all depends on a Box.Cache server
as this process will be the owner of the :ets
table that holds
the cached values.
Summary
Functions
Gets all record from a cache
Deletes a record by its key from the cache
Gets a record by its key
Inserts one or multiple records in the database with the provided options.
Memoizes a function in the given cache and under the given key. The function will
be applied then cached under the key if the value matches the cache_match
option.
By default, the value won't be cached if it's nil
, but one can override cache_match
to alter this and use, for instance &Box.Result.succeeded?/1
instead to only cache
records that matches {:ok, any()}
tuples.
Select record from a cache using a match spec
Types
@type cache() :: atom()
@type insert_option() :: {:ttl, non_neg_integer() | :infinity}
@type match() :: [tuple()]
@type record() :: {key(), value(), [record_option()]}
@type record_option() :: {:expiration, integer() | :never}
@type value() :: any()
Functions
Gets all record from a cache
Deletes a record by its key from the cache
Gets a record by its key
@spec insert(cache(), input_record() | [input_record()], [insert_option()]) :: :ok
Inserts one or multiple records in the database with the provided options.
Available options
ttl
: Time to live of the cache value.
@spec memoize(cache(), key(), [insert_option() | memoize_option()], (-> value())) :: value()
Memoizes a function in the given cache and under the given key. The function will
be applied then cached under the key if the value matches the cache_match
option.
By default, the value won't be cached if it's nil
, but one can override cache_match
to alter this and use, for instance &Box.Result.succeeded?/1
instead to only cache
records that matches {:ok, any()}
tuples.
Select record from a cache using a match spec