litellm/litellm/caching
Cesar Garcia 12284308a3
fix: Resolve MyPy type checking errors and CI linting (#16277)
* fix: Remove unused asyncio import from litellm_logging.py

- Fixes F401 linting error blocking CI

* fix: Add type ignore comments for MyPy false positives

- redis_cache.py: Add type ignore for aclose() - method exists but redis-py type stubs are incomplete
- redis_cluster_cache.py: Add type ignore for ping() and aclose() - redis-py typing issue
- responses/utils.py: Add type ignore for variable shadowing false positive
- transformation.py: Add type ignore for TypedDict expansion - runtime works correctly
- aws_secret_manager_v2.py: Add type ignore for dict[str, Any] assignment

All changes are safe - code works correctly in runtime, these are MyPy inference limitations.
Fixes 7 MyPy errors blocking CI without changing any logic.

* fix: Add type ignore for Redis async methods in cache files

- Add type: ignore[attr-defined] for aclose() in redis_cache.py
- Add type: ignore[attr-defined] for ping() and aclose() in redis_cluster_cache.py
- Methods exist but redis-py type stubs are incomplete

* refactor: Remove variable shadowing in _transform_response_api_usage_to_chat_usage

- Rename parameter 'usage' to 'usage_input' for clarity
- Rename local variable 'usage' to 'chat_usage' to avoid shadowing
- Eliminates MyPy false positive without needing type: ignore
- No functional changes - all tests pass
- Improves code readability and type safety
2025-11-05 18:36:06 -08:00
..
__init__.py Add GCS bucket caching support (#13122) 2025-08-04 16:09:33 -07:00
_internal_lru_cache.py
azure_blob_cache.py add azure blob cache support (#12587) 2025-07-15 11:47:38 -07:00
base_cache.py [Feat] UI - Allow setting cache settings on UI (#16143) 2025-10-31 17:43:59 -07:00
caching_handler.py [Fix] x-litellm-cache-key header not being returned on cache hit (#15348) 2025-10-08 18:10:43 -07:00
caching.py init asyc implementation 2025-08-21 10:22:54 +02:00
disk_cache.py [Bug Fix] No module named 'diskcache' (#11600) 2025-06-10 14:54:11 -07:00
dual_cache.py [Perf] Alexsander fixes round 2 - Oct 18th (#15695) 2025-10-18 11:12:00 -07:00
gcs_cache.py Add GCS bucket caching support (#13122) 2025-08-04 16:09:33 -07:00
in_memory_cache.py [Performance] Reduce complexity of InMemoryCache.evict_cache from O(n*log(n)) to O(log(n)) (#15000) 2025-09-30 16:49:35 -07:00
llm_caching_handler.py Fix pytest event loop warning (#10512) 2025-05-02 19:43:18 -07:00
qdrant_semantic_cache.py fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
Readme.md add azure blob cache support (#12587) 2025-07-15 11:47:38 -07:00
redis_cache.py fix: Resolve MyPy type checking errors and CI linting (#16277) 2025-11-05 18:36:06 -08:00
redis_cluster_cache.py fix: Resolve MyPy type checking errors and CI linting (#16277) 2025-11-05 18:36:06 -08:00
redis_semantic_cache.py build(pyproject.toml): add new dev dependencies - for type checking (#9631) 2025-03-29 11:02:13 -07:00
s3_cache.py clean imports 2025-08-25 11:09:06 +02:00

Caching on LiteLLM

LiteLLM supports multiple caching mechanisms. This allows users to choose the most suitable caching solution for their use case.

The following caching mechanisms are supported:

  1. RedisCache
  2. RedisSemanticCache
  3. QdrantSemanticCache
  4. InMemoryCache
  5. DiskCache
  6. S3Cache
  7. AzureBlobCache
  8. DualCache (updates both Redis and an in-memory cache simultaneously)

Folder Structure

litellm/caching/
├── base_cache.py
├── caching.py
├── caching_handler.py
├── disk_cache.py
├── dual_cache.py
├── in_memory_cache.py
├── qdrant_semantic_cache.py
├── redis_cache.py
├── redis_semantic_cache.py
├── s3_cache.py

Documentation