ttl_cache v0.1.0 TTLCache.Server

Link to this section Summary

Functions

Remove the key from the given cache

List all of the entries in the cache

Returns the value associated with the key key for the cache identified by pid

Modelled after Agent.get_and_update. Performs an atomic read-write operation. The special value of :TTLCache_delete can be returned by fun to atomically instead delete the value

Returns whether or not the key is in the cache

List all of the keys in the cache

Adds value to the cache identified by pid under the key key. The value will expire based on the TTL provided in TTLCache.Server.start_link/2

Creates a new server process

Stop the cache process

Updates the value associated with the key key for the cache identified by pid with the given fun. fun will run on the server process and will block the server until it returns. The TTL will not be refreshed. The special value of :TTLCache_delete can be returned by fun to atomically instead delete the value

List all of the values in the cache

Link to this section Functions

Link to this function delete(pid \\ TTLCache.Server.Global, key)

Remove the key from the given cache

Link to this function entries(pid \\ TTLCache.Server.Global)

List all of the entries in the cache

Link to this function get(pid \\ TTLCache.Server.Global, key)

Returns the value associated with the key key for the cache identified by pid

Link to this function get_and_update(pid \\ TTLCache.Server.Global, key, fun)

Modelled after Agent.get_and_update. Performs an atomic read-write operation. The special value of :TTLCache_delete can be returned by fun to atomically instead delete the value

Link to this function has_key?(pid \\ TTLCache.Server.Global, key)

Returns whether or not the key is in the cache

Link to this function keys(pid \\ TTLCache.Server.Global)

List all of the keys in the cache

Link to this function put(pid \\ TTLCache.Server.Global, key, value)

Adds value to the cache identified by pid under the key key. The value will expire based on the TTL provided in TTLCache.Server.start_link/2

Link to this function start_link(args, opts \\ [])

Creates a new server process.

Accepts the following options:

  • :ttl - whenever a value is added to the cache via put/3 it will expire based on this value (in milliseconds).

  • :on_expire - a callback that is triggered when an entry expires

  • :refresh_strategy - defines how to handle refreshing a key’s ttl

  • :expiration_strategy - defines how to expire keys

Link to this function stop(pid, reason \\ :normal)

Stop the cache process

Link to this function update(pid \\ TTLCache.Server.Global, key, fun)

Updates the value associated with the key key for the cache identified by pid with the given fun. fun will run on the server process and will block the server until it returns. The TTL will not be refreshed. The special value of :TTLCache_delete can be returned by fun to atomically instead delete the value

Link to this function values(pid \\ TTLCache.Server.Global)

List all of the values in the cache