Mnemonix v0.10.0 Mnemonix.Features.Expiry View Source
Functions to manage the time-to-live of entries within a store.
All of these functions are available on the main Mnemonix
module.
Link to this section Summary
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
Link to this section Types
The number of milliseconds an entry will be allowed to be retreived.
Link to this section Functions
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(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(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