Nebulex.Event.CacheEntryEvent (Nebulex v3.0.0-rc.1)
View SourceA 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() | 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 (for dynamic caches).:type
- The event type.:target
- The event target. It could be a key or a query (in case ofdelete_all
).:command
- The cache command triggering the event.:metadata
- The event metadata is provided when the listener is registered.
Type for the event target.
The event target can be a key or a query (for delete_all
command).
If the target is a key, it will come in the shape of {:key, deleted_key}
tuple. On the other hand, if the target is a query, it will come in the shape
of a {:query, {:in, deleted_keys}
tuple, or a {:query, {:q, query}
tuple.
@type type() :: :deleted | :expired | :inserted | :updated
Event type.
:deleted
- Invoked if a cache entry is deleted, or if a batch call is made, after the entries are deleted. The commandsdelete
anddelete_all
triggers this event.:expired
- Invoked if a cache entry or entries are evicted due to expiration.:inserted
- Invoked after a cache entry is inserted, or if a batch call is made after the entries are inserted. The commands triggering this event are:put
,put_new
,put_all
, andput_new_all
. Beware, forput
andput_all
commands, there is no way to know if the entry existed before the operation.:updated
- Invoked if an existing cache entry is updated viareplace
command.
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: :my_cache,
...> target: {:key, "foo"},
...> command: :put,
...> type: :inserted
...> )
%Nebulex.Event.CacheEntryEvent{
command: :put,
name: nil,
type: :inserted,
cache: :my_cache,
metadata: [],
target: {:key, "foo"}
}
@spec updated(Enumerable.t()) :: t()
Creates a new "updated" event.