Mnemonix v0.8.0 Mnemonix.Features.Expiry

Functions to manage the time-to-live of entries within a Mnemonix.Store.Server.

All of these functions are available on the main Mnemonix module.

Summary

Types

The number of milliseconds an entry will be allowed to be retreived

Functions

Sets the entry under key to expire in ttl milliseconds

Prevents the entry under key from expiring

Creates a new entry for value under key in store and sets it to expire in ttl milliseconds

Types

ttl()
ttl() :: non_neg_integer | nil

The number of milliseconds an entry will be allowed to be retreived.

Functions

expire(store, key, ttl \\ nil)
expire(Mnemonix.store, Mnemonix.key, ttl) ::
  Mnemonix.store |
  no_return

Sets the entry under key to expire in ttl milliseconds.

If the key does not exist, the contents of store will be unaffected.

If the entry under key was already set to expire, the new ttl will be used instead.

If the ttl is nil or not provided, it will defer to the ttl passed into the store’s options. If that was also nil, the entry will not be set to expire.

Examples

iex> store = Mnemonix.new(%{a: 1})
iex> Mnemonix.expire(store, :a, 1)
iex> :timer.sleep(200)
iex> Mnemonix.get(store, :a)
nil

iex> store = Mnemonix.new(%{a: 1})
iex> Mnemonix.expire(store, :a, 24 * 60 * 60 * 1)
iex> Mnemonix.expire(store, :a, 1)
iex> :timer.sleep(200)
iex> Mnemonix.get(store, :a)
nil
persist(store, key)
persist(Mnemonix.store, Mnemonix.key) ::
  Mnemonix.store |
  no_return

Prevents the entry under key from expiring.

If the key does not exist or is not set to expire, the contents of store will be unaffected.

Examples

iex> store = Mnemonix.new(%{a: 1})
iex> Mnemonix.expire(store, :a, 200)
iex> Mnemonix.persist(store, :a)
iex> :timer.sleep(200)
iex> Mnemonix.get(store, :a)
1
put_and_expire(store, key, value, ttl \\ nil)
put_and_expire(Mnemonix.store, Mnemonix.key, Mnemonix.value, ttl) ::
  Mnemonix.store |
  no_return

Creates a new entry for value under key in store and sets it to expire in ttl milliseconds.

If the ttl is nil or not provided, it will defer to the ttl passed into the store’s options. If that was also nil, the entry will not be set to expire.

Examples

iex> store = Mnemonix.new
iex> Mnemonix.put_and_expire(store, :a, "bar", 1)
iex> Mnemonix.get(store, :a)
"bar"
iex> :timer.sleep(200)
iex> Mnemonix.get(store, :a)
nil