ExLLM.Infrastructure.Cache.Storage behaviour (ex_llm v0.8.1)

View Source

Behaviour for cache storage backends.

This allows ExLLM to support different cache storage mechanisms like ETS, Redis, Memcached, etc.

Summary

Callbacks

Clear all entries from the cache.

Delete a key from the cache.

Get a value from the cache.

Get storage info/stats (optional).

Initialize the storage backend.

Get all keys matching a pattern (optional).

Put a value in the cache with expiration time.

Callbacks

clear(state)

@callback clear(state :: any()) :: {:ok, state :: any()}

Clear all entries from the cache.

delete(key, state)

@callback delete(key :: String.t(), state :: any()) :: {:ok, state :: any()}

Delete a key from the cache.

get(key, state)

@callback get(key :: String.t(), state :: any()) ::
  {:ok, value :: any(), state :: any()} | {:miss, state :: any()}

Get a value from the cache.

info(state)

@callback info(state :: any()) :: {:ok, info :: map(), state :: any()}

Get storage info/stats (optional).

init(opts)

@callback init(opts :: keyword()) :: {:ok, state :: any()} | {:error, reason :: any()}

Initialize the storage backend.

list_keys(pattern, state)

@callback list_keys(pattern :: String.t(), state :: any()) ::
  {:ok, keys :: [String.t()], state :: any()}

Get all keys matching a pattern (optional).

put(key, value, expires_at, state)

@callback put(key :: String.t(), value :: any(), expires_at :: integer(), state :: any()) ::
  {:ok, state :: any()}

Put a value in the cache with expiration time.