View Source Sanity.Cache.CacheServer (sanity_cache v0.4.0)

For caching results in an ETS table. A single instance of this GenServer is started automatically.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes a table if it exists. Returns :ok or {:error, :no_table}.

Fetches a value from the cache. Returns one of the following

Creates or replaces a table with the given names. pairs must be a map or a list of key value pairs like [{:my_key, :my_value}].

Link to this section Functions

Link to this function

cast_put_table(pid \\ Sanity.Cache.CacheServer, table, pairs)

View Source

Like put_table/3, except uses GenServer.cast/2.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delete_table(pid \\ Sanity.Cache.CacheServer, table)

View Source

Deletes a table if it exists. Returns :ok or {:error, :no_table}.

examples

Examples

iex> delete_table(:nonexistent_doctest_table)
{:error, :no_table}
Link to this function

fetch(pid \\ Sanity.Cache.CacheServer, table, key)

View Source

Fetches a value from the cache. Returns one of the following

  • {:ok, value} if the item is found
  • {:error, :no_table} if the table doesn't exist
  • {:error, :not_found} if the table exists but doesn't contain the specified key
Link to this function

put_table(pid \\ Sanity.Cache.CacheServer, table, pairs)

View Source

Creates or replaces a table with the given names. pairs must be a map or a list of key value pairs like [{:my_key, :my_value}].

examples

Examples

iex> put_table(:doctest_table, [{"key", "value"}])
:ok

See GenServer.start_link/3.