View Source Nebulex.Entry (Nebulex v2.4.1)

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

@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

Link to this function

decode(data, opts \\ [])

View Source
@spec decode(binary(), [term()]) :: term()

Decodes a previously encoded entry.

example

Example

iex> "hello"
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
"hello"
Link to this function

encode(data, opts \\ [])

View Source
@spec encode(term(), [term()]) :: binary()

Encodes a cache entry.

example

Example

iex> "hello"
...> |> Nebulex.Entry.encode()
...> |> Nebulex.Entry.decode()
"hello"
@spec expired?(t()) :: boolean()

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
@spec ttl(t()) :: timeout()

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