Nebulex.Adapters.Mnesia.Entry (nebulex_mnesia_adapter v2.6.5)
View SourceThis module defines a struct that represents a cache entry in the Mnesia adapter for Nebulex. It includes fields for the table name, key, value, last touched timestamp, and time-to-live (TTL) information.
Summary
Functions
Returns the key of the cache entry.
Returns the remaining TTL of the cache entry.
Returns the status of the cache entry.
Returns the TTL (time-to-live) of the cache entry.
Returns the value of the cache entry.
Types
@type t() :: {table :: atom(), key :: any(), value :: any(), touched :: integer(), ttl :: non_neg_integer() | :infinity}
Functions
Returns the key of the cache entry.
Parameters
- entry: A tuple representing the cache entry.
Examples
iex> entry = {:table, :key, "value", 1759420681791, 3600}
iex> Nebulex.Adapters.Mnesia.Entry.key(entry)
:key
Returns the remaining TTL of the cache entry.
Parameters
- entry: A tuple representing the cache entry.
Returns
- The remaining TTL in seconds, or
:infinityif the TTL is infinite. - Calculates remaining TTL as
ttl - (current_time - touched).
Examples
iex> entry = {:table, :key, "value", 1759420681791, 3600}
iex> Nebulex.Adapters.Mnesia.Entry.remaining_ttl(entry)
3595 # (assuming 5 seconds have passed since touched time)
iex> entry = {:table, :key, "value", 1759420681791, :infinity}
iex> Nebulex.Adapters.Mnesia.Entry.remaining_ttl(entry)
:infinity
@spec status(entry :: t()) :: {:ok, :active} | {:error, :expired}
Returns the status of the cache entry.
Parameters
- entry: A tuple representing the cache entry.
Returns
{:ok, :active}if the entry is valid.{:error, :expired}if the entry has expired.
Examples
iex> entry = {:table, :key, "value", 1759420681791, 3600}
iex> Nebulex.Adapters.Mnesia.Entry.status(entry)
{:ok, :active}
iex> entry = {:table, :key, "value", 1759420681791, 1}
iex> :timer.sleep(2000) # wait for 2 seconds
iex> Nebulex.Adapters.Mnesia.Entry.status(entry)
{:error, :expired}
@spec ttl(entry :: t()) :: non_neg_integer() | :infinity
Returns the TTL (time-to-live) of the cache entry.
Parameters
- entry: A tuple representing the cache entry.
Examples
iex> entry = {:table, :key, "value", 1759420681791, 3600}
iex> Nebulex.Adapters.Mnesia.Entry.ttl(entry)
3600
Returns the value of the cache entry.
Parameters
- entry: A tuple representing the cache entry.
Examples
iex> entry = {:table, :key, "value", 1759420681791, 3600}
iex> Nebulex.Adapters.Mnesia.Entry.value(entry)
"value"