Nebulex v1.1.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
cache()
View Source
cache() :: Nebulex.Cache.t()
cache() :: Nebulex.Cache.t()
key()
View Source
key() :: Nebulex.Cache.key()
key() :: Nebulex.Cache.key()
object()
View Source
object() :: Nebulex.Object.t()
object() :: Nebulex.Object.t()
opts()
View Source
opts() :: Nebulex.Cache.opts()
opts() :: Nebulex.Cache.opts()
t()
View Source
t() :: module()
t() :: module()
Link to this section Callbacks
__before_compile__(env)
View Source
__before_compile__(term(), env :: Macro.Env.t()) :: Macro.t()
__before_compile__(term(), env :: Macro.Env.t()) :: Macro.t()
The callback invoked in case the adapter needs to inject code.
delete(cache, key, opts) View Source
Deletes a single object from cache.
expire(cache, key, ttl) View Source
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.
flush(cache)
View Source
flush(cache()) :: :ok
flush(cache()) :: :ok
Flushes the cache.
get(cache, key, opts) View Source
Retrieves a single object from cache.
See Nebulex.Cache.get/2.
get_many(cache, list, opts) View Source
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.
has_key?(cache, key) View Source
Returns whether the given key exists in cache.
init(opts)
View Source
init(opts()) ::
{:ok, [:supervisor.child_spec() | {module(), term()} | module()]}
init(opts()) :: {:ok, [:supervisor.child_spec() | {module(), term()} | module()]}
Initializes the adapter supervision tree by returning the children
object_info(cache, key, attr) View Source
Returns the information associated with attr for the given key,
or returns nil if key doesn't exist.
set(cache, object, opts) View Source
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.
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 thekeyif it does not already exist. If it does,nilis returned.:replace- Alters the object stored underkey, but only if the object already exists into the cache.:set- Setkeyto hold the givenobject(default).
See Nebulex.Cache.set/3, Nebulex.Cache.add/3, Nebulex.Cache.replace/3.
set_many(cache, list, opts) View Source
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.
size(cache) View Source
Returns the total number of cached entries.
See Nebulex.Cache.size/0.
take(cache, key, opts) View Source
Returns and removes the object with key key in the cache.
See Nebulex.Cache.take/2.
update_counter(cache, key, incr, opts) View Source
Updates (increment or decrement) the counter mapped to the given key.