Vaultx.Cache.Adapters.Behaviour behaviour (Vaultx v0.7.0)
View SourceBehaviour 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
@type adapter_state() :: term()
@type cache_key() :: String.t()
@type cache_value() :: term()
@type ttl() :: pos_integer()
Callbacks
@callback cleanup(adapter_state()) :: :ok | {:error, term()}
Perform cleanup operations (remove expired entries, etc.).
@callback clear(:all | String.t(), adapter_state()) :: :ok | {:error, term()}
Clear cache entries matching a pattern.
@callback delete(cache_key(), adapter_state()) :: :ok | {:error, term()}
Delete a value from the cache.
@callback get(cache_key(), adapter_state()) :: {:ok, cache_value()} | {:error, :not_found} | {:error, term()}
Get a value from the cache.
@callback init(config :: map()) :: {:ok, adapter_state()} | {:error, term()}
Initialize the adapter with the given configuration.
@callback put(cache_key(), cache_value(), ttl(), adapter_state()) :: :ok | {:error, term()}
Put a value into the cache with TTL.
@callback stats(adapter_state()) :: {:ok, map()} | {:error, term()}
Get adapter statistics.