View Source Cachex.Actions (Cachex v3.6.0)

Parent actions module for cache interactions.

This module contains foundation actions required to implement cache actions, such as typical CRUD style operations on cache entries. It also provides the defaction/2 macro which enables command definition which injects notifications for cache hooks.

Link to this section Summary

Functions

Formats a fetched value into a Courier compatible tuple.

Normalizes a commit formatted fetch value.

Retrieves an entry from a cache.

Updates a collection of fields inside a cache entry.

Writes a new entry into a cache.

Returns the operation used for a write based on a prior value.

Link to this section Functions

Link to this function

format_fetch_value(value)

View Source

Formats a fetched value into a Courier compatible tuple.

If the value is tagged with :commit, :ignore or :error, it will be left alone; otherwise it will be wrapped and treated as a :commit Tuple.

Normalizes a commit formatted fetch value.

This is simply compatibility for the options addition in v3.5, without breaking the previous versions of this library.

@spec read(Spec.cache(), any()) :: Spec.entry() | nil

Retrieves an entry from a cache.

If the entry does not exist, a nil value will be returned. Likewise if the entry has expired, we lazily remove it (if enabled) and return a nil value.

This will return an instance of an entry record as defined in the main Cachex.Spec module, rather than just the raw value.

Link to this function

update(arg, key, changes)

View Source
@spec update(Spec.cache(), any(), [tuple()]) :: {:ok, boolean()}

Updates a collection of fields inside a cache entry.

This is done in a single call due to the use of :ets.update_element/3 which allows multiple changes in a group. This will return a boolean to represent whether the update was successful or not.

Note that updates are atomic; either all updates will take place, or none will.

@spec write(Spec.cache(), [Spec.entry()]) :: {:ok, boolean()}

Writes a new entry into a cache.

@spec write_op(atom()) :: atom()

Returns the operation used for a write based on a prior value.