# `Nebulex.Entry`
[🔗](https://github.com/elixir-nebulex/nebulex/blob/v2.6.6/lib/nebulex/entry.ex#L1)

Defines a Cache Entry.

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

# `t`

```elixir
@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.

# `decode`

```elixir
@spec decode(binary(), [term()]) :: term()
```

Decodes a previously encoded entry.

## Example

    iex> "hello"
    ...> |> Nebulex.Entry.encode()
    ...> |> Nebulex.Entry.decode()
    "hello"

# `encode`

```elixir
@spec encode(term(), [term()]) :: binary()
```

Encodes a cache entry.

## Example

    iex> "hello"
    ...> |> Nebulex.Entry.encode()
    ...> |> Nebulex.Entry.decode()
    "hello"

# `expired?`

```elixir
@spec expired?(t()) :: boolean()
```

Returns whether the given `entry` has expired or not.

## Example

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

    iex> Nebulex.Entry.expired?(
    ...>   %Nebulex.Entry{touched: Nebulex.Time.now() - 10, ttl: 1}
    ...> )
    true

# `ttl`

```elixir
@spec ttl(t()) :: timeout()
```

Returns the remaining time-to-live.

## 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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
