A cache entry event.
Summary
Functions
Returns the event types.
Creates a new deleted event.
Creates a new expired event.
Creates a new inserted event.
Creates a new event.
Creates a new updated event.
Types
@type t() :: %Nebulex.Event.CacheEntryEvent{ cache: Nebulex.Cache.t(), command: atom(), metadata: Nebulex.Event.metadata(), name: atom() | pid(), pid: pid() | nil, target: target(), type: type() }
Type for a cache entry event.
The event will have the following keys:
:cache- The defined cache module.:name- The cache name, or the cache PID when the cache was started without a name.:pid- The cache PID.:type- The event type.:target- The event target: a key, a list of keys, or a query. Seetarget/0.:command- The cache command that emitted the event.:metadata- The metadata given when the listener was registered. It also includes:extra_metadatawith the per-command metadata passed through the:telemetry_metadataruntime option.
Type for the event target.
The event can target a single key, a list of keys, or a query.
- A single key:
{:key, key}. A command writing or deleting a single key will use this target. E.g.,put,put_new,replace,delete, etc. - A list of keys:
{:in, [key1, key2, ...]}. A command writing or deleting multiple keys will use this target. E.g.,put_all,put_new_all, anddelete_all. - A query:
{:q, query}. A command deleting entries matching a query will use this target. E.g.,delete_all.
@type type() :: :deleted | :expired | :inserted | :updated
Event type.
:deleted- Emitted after an entry is deleted, or after a batch delete. The commandsdelete,take, anddelete_allemit it. Note thatdeleteemits it even when the key did not exist, since there is no way to know.:expired- Emitted when a read finds the entry expired. The commandsfetch,take,ttl, andhas_key?emit it.:inserted- Emitted after an entry is inserted, or after a batch insert. The commandsput,put_new,put_all, andput_new_allemit it, as doincranddecrwhen they create the counter. Note that forputandput_allthere is no way to know whether the entry existed before.:updated- Emitted when an existing entry changes. The commandsreplace,expire, andtouchemit it, as doincranddecrwhen the counter already exists.
Functions
@spec __types__() :: [atom()]
Returns the event types.
Example
iex> Nebulex.Event.CacheEntryEvent.__types__()
[:deleted, :expired, :inserted, :updated]
@spec deleted(Enumerable.t()) :: t()
Creates a new deleted event.
@spec expired(Enumerable.t()) :: t()
Creates a new expired event.
@spec inserted(Enumerable.t()) :: t()
Creates a new inserted event.
@spec new(Enumerable.t()) :: t()
Creates a new event.
Example
iex> Nebulex.Event.CacheEntryEvent.new(
...> cache: MyApp.Cache,
...> pid: self(),
...> target: {:key, "foo"},
...> command: :put,
...> type: :inserted
...> )
%Nebulex.Event.CacheEntryEvent{
cache: MyApp.Cache,
command: :put,
name: nil,
pid: self(),
type: :inserted,
metadata: %{},
target: {:key, "foo"}
}
@spec updated(Enumerable.t()) :: t()
Creates a new updated event.