Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. FastAPI
  3. FastAPI Cache

FastAPI Cache

Apache-2.0Pythonv0.2.2

A caching library for FastAPI that supports Redis, Memcached, DynamoDB, and in-memory backends with HTTP cache header support.

Visit WebsiteGitHubGitHub
1.9k stars207 forks0 contributors

What is FastAPI Cache?

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.

Target Audience

FastAPI developers building high-performance web APIs that need response caching, especially those using Redis, Memcached, or DynamoDB as cache stores.

Value Proposition

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.

Overview

fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.

Use Cases

Best For

  • Caching FastAPI endpoint responses to improve API response times
  • Reducing database load by caching frequently accessed query results
  • Implementing HTTP caching with ETag and Cache-Control headers in FastAPI
  • Using Redis or Memcached as a cache backend for FastAPI applications
  • Caching function results across distributed systems with DynamoDB
  • Adding transparent caching to existing FastAPI routes with minimal code changes

Not Ideal For

  • Applications requiring automatic background cleanup of expired cache entries, as the in-memory backend only removes them on access.
  • Teams not using FastAPI's type annotations extensively, since caching of Pydantic models depends on return type hints for proper deserialization.
  • Projects needing advanced cache invalidation strategies beyond simple time-based expiration, as the library focuses on basic expire mechanics without built-in event-driven invalidation.
  • Environments where Redis clients are configured with decode_responses=True, as this breaks caching due to binary data handling requirements.

Pros & Cons

Pros

Multiple Backend Flexibility

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.

Seamless FastAPI Integration

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.

HTTP Cache Header Support

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.

Customizable Caching Logic

Offers flexible cache key builders, expiration times, namespaces, and coders (JSON, Pickle, or custom), allowing fine-grained control over caching behavior through decorator parameters.

Cons

Type Annotation Reliance

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.

InMemoryBackend Limitations

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.

Dependency Injection Complexity

Injects request and response dependencies with fixed namespace keywords that could conflict with existing dependencies, requiring careful management and namespace adjustments in larger projects.

Frequently Asked Questions

Quick Stats

Stars1,872
Forks207
Contributors0
Open Issues76
Last commit1 year ago
CreatedSince 2020

Tags

#fastapi#caching#redis#python-library#api-performance#backend#cache#http-caching#dynamodb#memcached

Built With

F
FastAPI
D
DynamoDB
P
Python
M
Memcached
R
Redis

Links & Resources

Website

Included in

FastAPI11.2k
Auto-fetched 15 hours ago

Related Projects

Strawberry GraphQLStrawberry GraphQL

A GraphQL library for Python that leverages type annotations 🍓

Stars4,687
Forks653
Last commit22 hours ago
FastAPI UtilitiesFastAPI Utilities

Reusable utilities for FastAPI

Stars2,308
Forks191
Last commit1 year ago
SlowApiSlowApi

A rate limiter for Starlette and FastAPI

Stars2,036
Forks124
Last commit22 hours ago
FastAPI PaginationFastAPI Pagination

FastAPI pagination 📖

Stars1,674
Forks162
Last commit17 hours ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub