--- id: fastapi-cache2 version: "0.2.2" license: Apache-2.0 license_treatment: permissive maintenance: aging --- # fastapi-cache2 — Cache for FastAPI License: permissive · Maintenance: aging · Downloads: 1.1M/mo ## What it is and what it does fastapi-cache2 is a caching layer for FastAPI applications that transparently stores and retrieves endpoint and function results. It wraps your route handlers with a @cache decorator that automatically manages cache expiration, key generation, and backend storage. The package supports multiple backends—Redis, Memcached, DynamoDB, and in-memory—so you can choose the right storage for your deployment. The decorator integrates with FastAPI's dependency injection to handle HTTP cache semantics: it can set ETag and Cache-Control headers, return 304 Not Modified responses for conditional requests, and track cache hits and misses. You can customize cache behavior per endpoint with parameters like expiration time, namespace, and key-building strategy, or implement custom coders to handle non-JSON data types like Pydantic models and dataclasses. Use it for: - Cache API responses with automatic expiration to reduce database queries and improve endpoint latency. - Store results of expensive computations across multiple application instances using a shared backend. - Serve cached responses with proper HTTP cache headers and conditional request support for browser caching. - Cache function results in memory for single-instance deployments or testing without external dependencies. - Implement custom cache keys based on request method, URL, and query parameters instead of function arguments. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Caches FastAPI endpoint and function results with support for Redis, Memcached, DynamoDB, and in-memory backends, including HTTP cache header handling. Yes, with conditions. The package is straightforward to integrate and widely used, but its aging maintenance status (751 days since last release) means you should verify compatibility with your FastAPI and Python versions before adopting it. No known vulnerabilities. Choose this if you need transparent endpoint caching with multiple backend options; avoid if you require active maintenance or cutting-edge feature updates. ## Install pip install fastapi-cache2 uv add fastapi-cache2 poetry add fastapi-cache2 ## Installing fastapi-cache2 Before you install: Low install friction with five runtime dependencies. Maintenance status is aging—last release was 2024-07-24 and the repository has not been updated for 751 days, though it remains active and unarchived with 1866 stars. License in practice: Licensed under Apache-2.0 (permissive), allowing commercial use, modification, and distribution with minimal restrictions. Quickstart: pip install fastapi-cache2 from fastapi_cache import FastAPICache from fastapi_cache.decorator import cache FastAPICache.init(backend, prefix="fastapi-cache") @app.get("/") @cache(expire=60) async def index(): return dict(hello="world") Requires a running cache backend (Redis, Memcached, or DynamoDB) or uses in-memory storage; backend client configuration depends on chosen backend. Verify before relying: - Whether the aging maintenance status (751 days since last release) affects compatibility with recent FastAPI or Python versions. - Performance characteristics and memory overhead of the in-memory backend for production workloads. - Specific backend setup requirements and client library versions for Redis, Memcached, and DynamoDB. ## Package facts - License: Apache-2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 1.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags fastapi caching decorator, cache fastapi responses, http cache headers etag, memcached backend fastapi, dynamodb cache layer, response caching fastapi, cache control headers, caching, multi-backend, http-headers [View on SkillFed](https://skillfed.io/packages/fastapi-cache2) · [View on PyPI](https://pypi.org/project/fastapi-cache2/)