Nebulex v1.2.0 Nebulex.Object View Source

Defines a Cache Object.

This is the struct used by the caches to store and retrieve data.

Link to this section Summary

Functions

Returns the UNIX timestamp in seconds for the given ttl.

Returns whether the given object has expired or not.

Returns the remaining time to live for the given timestamp.

Link to this section Types

Link to this type

t()

View Source
t() :: %Nebulex.Object{
  expire_at: integer() | nil,
  key: any(),
  value: any(),
  version: any()
}

Link to this section Functions

Link to this function

decode(data, opts \\ [])

View Source
Link to this function

encode(data, opts \\ [])

View Source
Link to this function

expire_at(ttl)

View Source
expire_at(ttl :: timeout() | nil) :: integer() | nil

Returns the UNIX timestamp in seconds for the given ttl.

Example

iex> expire_at = Nebulex.Object.expire_at(10)
iex> expire_at - Nebulex.Object.ts()
10
Link to this function

expired?(object)

View Source
expired?(t()) :: boolean()

Returns whether the given object has expired or not.

Example

iex> Nebulex.Object.expired?(%Nebulex.Object{})
false
Link to this function

remaining_ttl(expire_at)

View Source
remaining_ttl(object_or_ttl :: t() | integer() | nil) :: timeout()

Returns the remaining time to live for the given timestamp.

Example

iex> expire_at = Nebulex.Object.expire_at(10)
iex> Nebulex.Object.remaining_ttl(expire_at)
10
Link to this function

ts(datetime \\ DateTime.utc_now())

View Source
ts(datetime :: Calendar.datetime()) :: integer()

Wrapper for DateTime.to_unix/2.

Example

iex> 1_464_096_368 |> DateTime.from_unix!() |> Nebulex.Object.ts()
1464096368