Cachex v3.1.3 Cachex.Actions View Source

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

Normalizes a value into a Courier-friendly tagged Tuple

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 macro normalize_commit(value) View Source (macro)

Normalizes a value into a Courier-friendly tagged 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.

Link to this function read(cache, key) View Source
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
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.

Link to this function write(arg, entries) View Source
write(Spec.cache(), [Spec.entry()]) :: {:ok, boolean()}

Writes a new entry into a cache.

Link to this function write_op(arg1) View Source
write_op(atom()) :: atom()

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