View Source Nebulex.Entry (Nebulex v2.5.2)
Defines a Cache Entry.
This is the structure used by the caches for representing cache entries.
Link to this section 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.
Link to this section 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.
Link to this section Functions
Decodes a previously encoded entry.
example
Example
iex> "hello"
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
"hello"
Encodes a cache entry.
example
Example
iex> "hello"
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
"hello"
Returns whether the given entry
has expired or not.
example
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
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