XepCache v1.0.0 XepCache

A wrapper around Erlang's depcache, an in-memory caching server.

depcache bases its caching around ETS but can also switch to using the in-process dictionary for maintaining a process-local cache. Convenient functions are provided for getting/setting cache values, with ttl and cache key dependencies, as well as a memo function for caching the result of function executions.

Options

Most functions take an opts argument which holds various options.

  • :ttl - the maximum time-to-live of the cached value. When the cached value is older than the time, it will be marked as expired.

  • :deps - an array of cache keys which the given key depends on. This can be used to invalidate an entire tree of keys just by flushing one "parent" key on which these all depend.

  • :server - the name of the depcache server. By default, the xepcache application starts a single depcache instance, registered under the default name :depcache. This is also the default argument for this option, so it can be omitted usually.

Summary

Functions

Flush the key and all keys depending on the key

Flush all keys from the caches for given server or the default server

Fetch the key from the cache, return the data or nil if not found

Check if we use a local process dict cache

Enable or disable the in-process caching using the process dictionary

Adds the result of the given function to the depcache. The function is only called when there is a cache miss; otherwise, the cached value is returned

Add a key to the depcache with a given value. :ttl option gives the maximum key expiry; :deps option gives an array of cache keys which this key depends on

Callback implementation for c::application.start/2

Functions

flush(key)
flush(key, opts)

Flush the key and all keys depending on the key

flush_all()
flush_all(server)

Flush all keys from the caches for given server or the default server

get(key)
get(key, opts)

Fetch the key from the cache, return the data or nil if not found.

in_process()

Check if we use a local process dict cache

in_process(flag)

Enable or disable the in-process caching using the process dictionary

memo(fun)
memo(fun, key)
memo(fun, key, opts)

Adds the result of the given function to the depcache. The function is only called when there is a cache miss; otherwise, the cached value is returned.

set(key, value)
set(key, value, opts)

Add a key to the depcache with a given value. :ttl option gives the maximum key expiry; :deps option gives an array of cache keys which this key depends on.

start(type, args)

Callback implementation for c::application.start/2.