simplecache v0.1.0 Simplecache

An abstract cache store. There are multiple cache store implementations, each having its own additional features.

Some implementations may not support all methods beyond the basic cache methods of fetch, write, read, exist, and delete.

Link to this section Summary

Functions

Deletes an entry in the cache. Returns true if an entry is deleted.

Returns true if the cache contains an entry for the given key.

Fetches data from the cache, using the given key. If there is data in the cache with the given key, then that data is returned.

Fetches the value for the given key from the cache.

Writes the value to the cache, with the key.

Link to this section Functions

Link to this function

delete(key, options \\ [])

Deletes an entry in the cache. Returns true if an entry is deleted.

Options are passed to the underlying cache implementation.

Examples

iex> Simplecache.delete("foo")
true
Link to this function

exist(key, options \\ [])

Returns true if the cache contains an entry for the given key.

Options are passed to the underlying cache implementation.

Examples

iex> Simplecache.exist("not_there")
false

iex> Simplecache.write("there", "it is")
:ok

iex> Simplecache.exist("there")
true
Link to this function

fetch(key, fun)

Fetches data from the cache, using the given key. If there is data in the cache with the given key, then that data is returned.

Given function will be executed in the event of a cache miss. The return value of the function will be written to the cache under the given cache key, and that return value will be returned.

Examples

iex> Simplecache.fetch("foo", fn -> "bar" end)
"bar"

iex> Simplecache.fetch("foo", fn -> "bar2" end)
"bar"

Fetches the value for the given key from the cache.

Examples

iex> Simplecache.read("test")
nil
Link to this function

write(key, data, options \\ [])

Writes the value to the cache, with the key.

Options are passed to the underlying cache implementation.

Examples

iex> Simplecache.write("foo", "bar")
:ok