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

View Source

Specialized storage backend for timestamp-based test response caching.

This module provides hierarchical organization by provider/test module/scenario with timestamp-based file naming, rich metadata indexing, content deduplication, and smart fallback strategies for test response caching.

Summary

Functions

Clear cache entries for a specific cache key or pattern.

Check if a cached response exists and is valid.

Retrieve a cached response using TTL and fallback strategy.

Get cache statistics for a specific key or all keys.

List all available cache keys.

Store a test response with timestamp-based naming.

Types

cache_entry()

@type cache_entry() :: %{
  timestamp: DateTime.t(),
  filename: String.t(),
  status: :success | :error | :timeout,
  size: non_neg_integer(),
  content_hash: String.t(),
  response_time_ms: non_neg_integer(),
  api_version: String.t() | nil,
  cost: map() | nil
}

cache_key()

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

fallback_strategy()

@type fallback_strategy() :: :latest_success | :latest_any | :best_match

Functions

clear(cache_key)

@spec clear(cache_key() | :all) :: :ok | {:error, term()}

Clear cache entries for a specific cache key or pattern.

exists?(cache_key)

@spec exists?(cache_key()) :: boolean()

Check if a cached response exists and is valid.

get(cache_key, options \\ %{})

@spec get(cache_key(), map()) :: {:ok, any()} | {:error, term()} | :miss

Retrieve a cached response using TTL and fallback strategy.

get_stats(cache_key)

@spec get_stats(cache_key() | :all) :: map()

Get cache statistics for a specific key or all keys.

list_cache_keys()

@spec list_cache_keys() :: [cache_key()]

List all available cache keys.

store(cache_key, response_data, metadata \\ %{})

@spec store(cache_key(), any(), map()) :: :ok | {:error, term()}

Store a test response with timestamp-based naming.