View Source Nebulex.Adapter.Entry behaviour (Nebulex v2.6.1)

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

Link to this callback

delete(adapter_meta, key, opts)

View Source
@callback delete(adapter_meta(), key(), opts()) :: :ok

Deletes a single entry from cache.

See Nebulex.Cache.delete/2.

Link to this callback

expire(adapter_meta, key, ttl)

View Source
@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.

See Nebulex.Cache.expire/2.

Link to this callback

get(adapter_meta, key, opts)

View Source
@callback get(adapter_meta(), key(), opts()) :: value()

Gets the value for a specific key in cache.

See Nebulex.Cache.get/2.

Link to this callback

get_all(adapter_meta, list, opts)

View Source
@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.

See Nebulex.Cache.get_all/2.

Link to this callback

has_key?(adapter_meta, key)

View Source
@callback has_key?(adapter_meta(), key()) :: boolean()

Returns whether the given key exists in cache.

See Nebulex.Cache.has_key?/1.

Link to this callback

put(adapter_meta, key, value, ttl, on_write, opts)

View Source
@callback put(adapter_meta(), key(), value(), ttl(), on_write(), opts()) :: boolean()

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 the key already exists, it is overwritten. Any previous time-to-live associated with the key is discarded on successful write operation.

  • :put_new - It only stores the entry if the key does not already exist, otherwise, false is returned.

  • :replace - Alters the value stored under the given key, but only if the key already exists into the cache, otherwise, false is returned.

See Nebulex.Cache.put/3, Nebulex.Cache.put_new/3, Nebulex.Cache.replace/3.

Link to this callback

put_all(adapter_meta, entries, ttl, on_write, opts)

View Source
@callback put_all(adapter_meta(), entries(), ttl(), on_write(), opts()) :: boolean()

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 the key already exists, it is overwritten. Any previous time-to-live associated with the key is discarded on successful write operation.

  • :put_new - It only stores the entry if the key does not already exist, otherwise, false is 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.

See Nebulex.Cache.put_all/2.

Link to this callback

take(adapter_meta, key, opts)

View Source
@callback take(adapter_meta(), key(), opts()) :: value()

Returns and removes the entry with key key in the cache.

See Nebulex.Cache.take/2.

Link to this callback

touch(adapter_meta, key)

View Source
@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.

See Nebulex.Cache.touch/1.

@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.

Link to this callback

update_counter(adapter_meta, key, amount, ttl, default, opts)

View Source
@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.