A caching library for FastAPI that supports Redis, Memcached, DynamoDB, and in-memory backends with HTTP cache header support.
fastapi-cache is a Python library that adds caching capabilities to FastAPI applications. It allows developers to cache endpoint responses and function results using decorators, with support for multiple backend stores like Redis, Memcached, and DynamoDB. It solves performance bottlenecks by reducing repetitive computations and database calls in API routes.
FastAPI developers building high-performance web APIs that need response caching, especially those using Redis, Memcached, or DynamoDB as cache stores.
Developers choose fastapi-cache for its seamless integration with FastAPI, support for multiple backends, HTTP cache header compliance, and flexible caching strategies without boilerplate code.
fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports Redis, Memcached, DynamoDB, and in-memory storage, allowing teams to choose based on infrastructure needs, as shown in the installation extras and backend options in the README.
Uses a simple decorator-based API that fits naturally into FastAPI route handlers, with examples in the README showing minimal code changes for caching endpoints and functions.
Enables efficient client-side caching by handling ETag and Cache-Control headers and supporting conditional requests like If-Non-Match, reducing server load as highlighted in the features.
Offers flexible cache key builders, expiration times, namespaces, and coders (JSON, Pickle, or custom), allowing fine-grained control over caching behavior through decorator parameters.
For caching complex types like Pydantic models, return type annotations are mandatory; without them, the cache reverts to primitive JSON, limiting usability in annotation-light codebases as warned in the README.
The in-memory backend does not automatically purge expired keys unless accessed, potentially leading to memory bloat in long-running applications, a noted drawback in the backend notes.
Injects request and response dependencies with fixed namespace keywords that could conflict with existing dependencies, requiring careful management and namespace adjustments in larger projects.