Implementation:BerriAI Litellm Cache Type Enum
| Knowledge Sources | https://github.com/BerriAI/litellm |
|---|---|
| Domains | Caching, LLM Infrastructure, Type Definitions |
| Last Updated | 2026-02-15 |
Overview
Concrete type definition for selecting a cache backend provided by the LiteLLM library.
Description
The LiteLLMCacheType class is a string-based enumeration that defines all supported cache storage backends in LiteLLM. It serves as the single source of truth for valid cache type identifiers and is consumed by the Cache.__init__ constructor to determine which concrete backend to instantiate. In addition to the enum, the module defines supporting types: CachingSupportedCallTypes (a Literal type constraining which LLM call types can be cached), DynamicCacheControl (a TypedDict for per-request cache directives like TTL, namespace, and no-cache/no-store flags), CachePingResponse and HealthCheckCacheParams (Pydantic models for cache health check API responses), and RedisPipelineIncrementOperation / RedisPipelineSetOperation (TypedDicts for batched Redis pipeline operations).
Usage
Import LiteLLMCacheType when initializing a Cache object to specify the desired backend. Import CachingSupportedCallTypes when filtering which LLM operations are eligible for caching. Import DynamicCacheControl when constructing per-request cache control headers.
Code Reference
| Source Location | litellm/types/caching.py, lines 8-101
|
|---|---|
| Signature | class LiteLLMCacheType(str, Enum)
|
| Import | from litellm.types.caching import LiteLLMCacheType
|
Enum Members:
class LiteLLMCacheType(str, Enum):
LOCAL = "local"
REDIS = "redis"
REDIS_SEMANTIC = "redis-semantic"
S3 = "s3"
DISK = "disk"
QDRANT_SEMANTIC = "qdrant-semantic"
AZURE_BLOB = "azure-blob"
GCS = "gcs"
Supporting Types:
CachingSupportedCallTypes = Literal[
"completion", "acompletion", "embedding", "aembedding",
"atranscription", "transcription", "atext_completion",
"text_completion", "arerank", "rerank", "responses", "aresponses",
]
DynamicCacheControl = TypedDict(
"DynamicCacheControl",
{
"ttl": Optional[int],
"namespace": Optional[str],
"s-maxage": Optional[int],
"s-max-age": Optional[int],
"no-cache": Optional[bool],
"no-store": Optional[bool],
},
)
I/O Contract
Inputs:
| Parameter | Type | Description |
|---|---|---|
| (N/A -- enum instantiation) | str |
One of the string values: "local", "redis", "redis-semantic", "s3", "disk", "qdrant-semantic", "azure-blob", "gcs"
|
Outputs:
| Return Type | Description |
|---|---|
LiteLLMCacheType |
An enum member representing the selected cache backend |
Usage Examples
Selecting a cache type for Redis:
from litellm.types.caching import LiteLLMCacheType
# Use the enum to specify Redis as the cache backend
cache_type = LiteLLMCacheType.REDIS
print(cache_type.value) # "redis"
Using the enum during Cache initialization:
from litellm.caching.caching import Cache
from litellm.types.caching import LiteLLMCacheType
# Initialize a local in-memory cache
cache = Cache(type=LiteLLMCacheType.LOCAL)
# Initialize a Redis cache
cache = Cache(
type=LiteLLMCacheType.REDIS,
host="redis.example.com",
port="6379",
password="secret",
)
Checking supported call types:
from litellm.types.caching import CachingSupportedCallTypes
from typing import get_args
# List all call types that support caching
supported = get_args(CachingSupportedCallTypes)
print(supported)
# ('completion', 'acompletion', 'embedding', 'aembedding', ...)
Using DynamicCacheControl for per-request cache directives:
from litellm.types.caching import DynamicCacheControl
# Bypass cache for a specific request
cache_control: DynamicCacheControl = {"no-cache": True}
# Set a custom TTL and namespace
cache_control: DynamicCacheControl = {"ttl": 3600, "namespace": "prod-v2"}