Vaultx.Cache.Adapters.Behaviour behaviour (Vaultx v0.7.0)

View Source

Behaviour for L2 cache adapters.

This behaviour defines the interface that all L2 cache adapters must implement. Adapters can be for Redis, Memcached, or any other distributed caching system.

Summary

Callbacks

Perform cleanup operations (remove expired entries, etc.).

Clear cache entries matching a pattern.

Delete a value from the cache.

Get a value from the cache.

Initialize the adapter with the given configuration.

Put a value into the cache with TTL.

Get adapter statistics.

Types

adapter_state()

@type adapter_state() :: term()

cache_key()

@type cache_key() :: String.t()

cache_value()

@type cache_value() :: term()

ttl()

@type ttl() :: pos_integer()

Callbacks

cleanup(adapter_state)

@callback cleanup(adapter_state()) :: :ok | {:error, term()}

Perform cleanup operations (remove expired entries, etc.).

clear(arg1, adapter_state)

@callback clear(:all | String.t(), adapter_state()) :: :ok | {:error, term()}

Clear cache entries matching a pattern.

delete(cache_key, adapter_state)

@callback delete(cache_key(), adapter_state()) :: :ok | {:error, term()}

Delete a value from the cache.

get(cache_key, adapter_state)

@callback get(cache_key(), adapter_state()) ::
  {:ok, cache_value()} | {:error, :not_found} | {:error, term()}

Get a value from the cache.

init(config)

@callback init(config :: map()) :: {:ok, adapter_state()} | {:error, term()}

Initialize the adapter with the given configuration.

put(cache_key, cache_value, ttl, adapter_state)

@callback put(cache_key(), cache_value(), ttl(), adapter_state()) ::
  :ok | {:error, term()}

Put a value into the cache with TTL.

stats(adapter_state)

@callback stats(adapter_state()) :: {:ok, map()} | {:error, term()}

Get adapter statistics.