View Source Cache behaviour (elixir_cache v0.1.0)

ElixirCache

Test Credo Dialyzer Coverage

The goal of this project is to unify Cache APIs and make Strategies easy to implement and sharable across all storage types/adapters

The second goal is to make sure testing of all cache related funciions is easy, meaning caches should be isolated per test and not leak their state to outside tests

installation

Installation

The package can be installed by adding elixir_cache to your list of dependencies in mix.exs:

def deps do
  [
    {:elixir_cache, "~> 0.1.0"}
  ]
end

The docs can be found at https://hexdocs.pm/elixir_cache.

usage

Usage

defmodule MyModule do
  use Cache,
    adapter: Cache.Redis,
    name: :my_name,
    sandbox?: Mix.env() === :test,
    opts: [...otps]
end

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for Supervisor.init/1.

Link to this section Callbacks

@callback child_spec({cache_name :: atom(), cache_opts :: Keyword.t()}) ::
  Supervisor.child_spec() | :supervisor.child_spec()
@callback delete(cache_name :: atom(), key :: atom() | String.t()) ::
  :ok | ErrorMessage.t()
Link to this callback

delete(cache_name, key, opts)

View Source
@callback delete(cache_name :: atom(), key :: atom() | String.t(), opts :: Keyword.t()) ::
  :ok | ErrorMessage.t()
@callback get(cache_name :: atom(), key :: atom() | String.t()) ::
  ErrorMessage.t_res(any())
@callback get(cache_name :: atom(), key :: atom() | String.t(), Keyword.t()) ::
  ErrorMessage.t_res(any())
@callback opts_definition() :: Keyword.t()
Link to this callback

put(cache_name, key, ttl, value)

View Source
@callback put(
  cache_name :: atom(),
  key :: atom() | String.t(),
  ttl :: pos_integer(),
  value :: any()
) ::
  :ok | ErrorMessage.t()
Link to this callback

put(cache_name, key, ttl, value, t)

View Source
@callback put(
  cache_name :: atom(),
  key :: atom() | String.t(),
  ttl :: pos_integer(),
  value :: any(),
  Keyword.t()
) :: :ok | ErrorMessage.t()

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Callback implementation for Supervisor.init/1.

Link to this function

start_link(cache_children, opts \\ [])

View Source