View Source Nebulex.Adapter.Entry behaviour (Nebulex v2.6.4)
Specifies the entry API required from adapters.
This behaviour specifies all read/write key-based functions, the ones applied to a specific cache entry.
Summary
Types
Proxy type to the adapter meta
Proxy type to the cache entries
Proxy type to the cache key
Write command
Proxy type to the cache options
TTL for a cache entry
Proxy type to the cache value
Callbacks
Deletes a single entry from cache.
Returns true if the given key exists and the new ttl was successfully
updated, otherwise, false is returned.
Gets the value for a specific key in cache.
Gets a collection of entries from the Cache, returning them as Map.t() of
the values associated with the set of keys requested.
Returns whether the given key exists in cache.
Puts the given value under key into the cache.
Puts the given entries (key/value pairs) into the cache.
Returns and removes the entry with key key in the cache.
Returns true if the given key exists and the last access time was
successfully updated, otherwise, false is returned.
Returns the TTL (time-to-live) for the given key. If the key does not
exist, then nil is returned.
Updates the counter mapped to the given key.
Types
@type adapter_meta() :: Nebulex.Adapter.adapter_meta()
Proxy type to the adapter meta
@type entries() :: Nebulex.Cache.entries()
Proxy type to the cache entries
@type key() :: Nebulex.Cache.key()
Proxy type to the cache key
@type on_write() :: :put | :put_new | :replace
Write command
@type opts() :: Nebulex.Cache.opts()
Proxy type to the cache options
@type ttl() :: timeout()
TTL for a cache entry
@type value() :: Nebulex.Cache.value()
Proxy type to the cache value
Callbacks
@callback delete(adapter_meta(), key(), opts()) :: :ok
Deletes a single entry from cache.
@callback expire(adapter_meta(), key(), ttl()) :: boolean()
Returns true if the given key exists and the new ttl was successfully
updated, otherwise, false is returned.
@callback get(adapter_meta(), key(), opts()) :: value()
Gets the value for a specific key in cache.
See Nebulex.Cache.get/2.
@callback get_all(adapter_meta(), [key()], opts()) :: map()
Gets a collection of entries from the Cache, returning them as Map.t() of
the values associated with the set of keys requested.
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.
@callback has_key?(adapter_meta(), key()) :: boolean()
Returns whether the given key exists in cache.
Puts the given value under key into the cache.
Returns true if the value with key key is successfully inserted;
otherwise false is returned.
The ttl argument sets the time-to-live for the stored entry. If it is not
set, it means the entry hasn't a time-to-live, then it shouldn't expire.
OnWrite
The on_write argument supports the following values:
:put- If thekeyalready exists, it is overwritten. Any previous time-to-live associated with the key is discarded on successfulwriteoperation.:put_new- It only stores the entry if thekeydoes not already exist, otherwise,falseis returned.:replace- Alters the value stored under the givenkey, but only if the key already exists into the cache, otherwise,falseis returned.
See Nebulex.Cache.put/3, Nebulex.Cache.put_new/3,
Nebulex.Cache.replace/3.
Puts the given entries (key/value pairs) into the cache.
Returns true if all the keys were inserted. If no key was inserted
(at least one key already existed), false is returned.
The ttl argument sets the time-to-live for the stored entry. If it is not
set, it means the entry hasn't a time-to-live, then it shouldn't expire.
The given ttl is applied to all keys.
OnWrite
The on_write argument supports the following values:
:put- If thekeyalready exists, it is overwritten. Any previous time-to-live associated with the key is discarded on successfulwriteoperation.:put_new- It only stores the entry if thekeydoes not already exist, otherwise,falseis returned.
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.
@callback take(adapter_meta(), key(), opts()) :: value()
Returns and removes the entry with key key in the cache.
See Nebulex.Cache.take/2.
@callback touch(adapter_meta(), key()) :: boolean()
Returns true if the given key exists and the last access time was
successfully updated, otherwise, false is returned.
@callback ttl(adapter_meta(), key()) :: ttl() | nil
Returns the TTL (time-to-live) for the given key. If the key does not
exist, then nil is returned.
See Nebulex.Cache.ttl/1.
@callback update_counter(adapter_meta(), key(), amount, ttl(), default, opts()) :: integer() when amount: integer(), default: integer()
Updates the counter mapped to the given key.
If amount > 0, the counter is incremented by the given amount.
If amount < 0, the counter is decremented by the given amount.
If amount == 0, the counter is not updated.
See Nebulex.Cache.incr/3.
See Nebulex.Cache.decr/3.