Nebulex.Entry (Nebulex v2.0.0) View Source

Defines a Cache Entry.

This is the structure used by the caches for representing cache entries.

Link to this section Summary

Types

t()

Defines a generic struct for a cache entry.

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

Specs

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

Link to this function

decode(data, opts \\ [])

View Source

Specs

decode(binary(), [term()]) :: term()

Decodes a previously encoded entry.

Example

iex> %Nebulex.Entry{}
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
_decoded_entry
Link to this function

encode(data, opts \\ [])

View Source

Specs

encode(term(), [term()]) :: binary()

Encodes a cache entry.

Example

iex> Nebulex.Entry.encode(%Nebulex.Entry{})
_encoded_entry

Specs

expired?(t()) :: boolean()

Returns whether the given entry has expired or not.

Example

iex> Nebulex.Entry.expired?(%Nebulex.Entry{})
false

Specs

ttl(t()) :: timeout()

Returns the remaining time-to-live.

Example

iex> Nebulex.Entry.ttl(%Nebulex.Entry{})
:infinity