View Source Nebulex.Entry (Nebulex v2.6.4)
Defines a Cache Entry.
This is the structure used by the caches for representing cache entries.
Summary
Functions
Decodes a previously encoded entry.
Encodes a cache entry.
Returns whether the given entry
has expired or not.
Returns the remaining time-to-live.
Types
@type t() :: %Nebulex.Entry{ key: any(), time_unit: System.time_unit(), touched: integer(), ttl: timeout(), value: any() }
Defines a generic struct for a cache entry.
The entry depends on the adapter completely, this struct/type aims to define the common fields.
Functions
Decodes a previously encoded entry.
Example
iex> "hello"
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
"hello"
Encodes a cache entry.
Example
iex> "hello"
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
"hello"
Returns whether the given entry
has expired or not.
Example
iex> Nebulex.Entry.expired?(%Nebulex.Entry{})
false
iex> Nebulex.Entry.expired?(
...> %Nebulex.Entry{touched: Nebulex.Time.now() - 10, ttl: 1}
...> )
true
Returns the remaining time-to-live.
Example
iex> Nebulex.Entry.ttl(%Nebulex.Entry{})
:infinity
iex> ttl =
...> Nebulex.Entry.ttl(
...> %Nebulex.Entry{touched: Nebulex.Time.now(), ttl: 100}
...> )
iex> ttl > 0
true