Nebulex v1.2.0 Nebulex.Adapter behaviour View Source
This module specifies the adapter API that a Cache adapter is required to implement.
Link to this section Summary
Callbacks
The callback invoked in case the adapter needs to inject code.
Deletes a single object from cache.
Returns the expiry timestamp for the given key
, if the timeout ttl
(in seconds) is successfully updated.
Flushes the cache.
Retrieves a single object from cache.
Returns a map with the objects for all specified keys. For every key that does not hold a value or does not exist, that key is simply ignored. Because of this, the operation never fails.
Returns whether the given key
exists in cache.
Initializes the adapter supervision tree by returning the children
Returns the information associated with attr
for the given key
,
or returns nil
if key
doesn't exist.
Sets the given object
under key
into the cache.
Sets the given objects
, replacing existing ones, just as regular set
.
Returns the total number of cached entries.
Returns and removes the object with key key
in the cache.
Updates (increment or decrement) the counter mapped to the given key
.
Link to this section Types
Link to this section Callbacks
__before_compile__(env)
View Source__before_compile__(term(), env :: Macro.Env.t()) :: Macro.t()
The callback invoked in case the adapter needs to inject code.
Deletes a single object from cache.
Returns the expiry timestamp for the given key
, if the timeout ttl
(in seconds) is successfully updated.
If key
doesn't exist, nil
is returned.
Flushes the cache.
Retrieves a single object from cache.
See Nebulex.Cache.get/2
.
Returns a map with the objects for all specified keys. For every key that does not hold a value or does not exist, that key is simply ignored. Because of this, the operation never fails.
Returns whether the given key
exists in cache.
init(opts)
View Sourceinit(opts()) :: {:ok, [:supervisor.child_spec() | {module(), term()} | module()]}
Initializes the adapter supervision tree by returning the children
Returns the information associated with attr
for the given key
,
or returns nil
if key
doesn't exist.
Sets the given object
under key
into the cache.
If the object already exists, it is overwritten. Any previous time to live
associated with the key is discarded on successful set
operation.
Returns true
if an object with key key
is found and successfully inserted,
otherwise false
.
Options
Besides the "Shared options" section in Nebulex.Cache
documentation,
it accepts:
:action
- It may be one of:add
,:replace
,:set
(the default). See the "Actions" section for more information.
Actions
The :action
option supports the following values:
:add
- Only set thekey
if it does not already exist. If it does,false
is returned.:replace
- Alters the object stored underkey
, but only if the object already exists into the cache.:set
- Setkey
to hold the givenobject
(default).
See Nebulex.Cache.set/3
, Nebulex.Cache.add/3
, Nebulex.Cache.replace/3
.
Sets the given objects
, replacing existing ones, just as regular set
.
Returns :ok
if the all objects were successfully set, otherwise
{:error, failed_keys}
, where failed_keys
contains the keys that
could not be set.
Ideally, this operation should be atomic, so all given keys are set at once. But it depends purely on the adapter's implementation and the backend used internally by the adapter. Hence, it is recommended to checkout the adapter's documentation.
Returns the total number of cached entries.
See Nebulex.Cache.size/0
.
Returns and removes the object with key key
in the cache.
See Nebulex.Cache.take/2
.
Updates (increment or decrement) the counter mapped to the given key
.