Skip to main content

FastAPI simple cache

Project description

FastAPI Cache Plus

Static Badge GitHub License GitHub Actions Workflow Status codecov PyPI - Version

This project is a continuation of the project fastapi_cache. Many thanks to Ivan Sushkov (the original author) for their work and contributions.

Implements simple lightweight cache system as dependencies in FastAPI.

Installation

pip install fastapi-cache-plus

Usage example

from fastapi import Depends, FastAPI

from fastapi_cache_plus import caches, close_caches
from fastapi_cache_plus.backends.redis import CACHE_KEY, RedisCacheBackend

app = FastAPI()


def redis_cache():
    return caches.get(CACHE_KEY)


@app.get("/")
async def hello(cache: RedisCacheBackend = Depends(redis_cache)):
    in_cache = await cache.get("some_cached_key")
    if not in_cache:
        await cache.set("some_cached_key", "new_value", 5)

    return {"response": in_cache or "default"}


@app.on_event("startup")
async def on_startup() -> None:
    rc = RedisCacheBackend("redis://redis")
    caches.set(CACHE_KEY, rc)


@app.on_event("shutdown")
async def on_shutdown() -> None:
    await close_caches()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_cache_plus-0.2.0.tar.gz (74.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_cache_plus-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_cache_plus-0.2.0.tar.gz.

File metadata

  • Download URL: fastapi_cache_plus-0.2.0.tar.gz
  • Upload date:
  • Size: 74.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for fastapi_cache_plus-0.2.0.tar.gz
Algorithm Hash digest
SHA256 526241a2340a8ecf1ecedefab480da8aec128c4c17d32397d6617d49d6094f81
MD5 fa18c8fe6239c3d53c36ee3c5d0cae30
BLAKE2b-256 84ca44243c7bdcc017c2d52397c0ad6fc8330695d8609d06e00175e29f99c4ea

See more details on using hashes here.

File details

Details for the file fastapi_cache_plus-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_cache_plus-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a3f243eab144650e86b4d1d28e3234f2ffc4289d21504b04dc9ed6aa399cc1d
MD5 ff147b0764c56576e245403204db10e8
BLAKE2b-256 7e7ec5831ceae4f950547b336b579900682b66e519ede23a97df7577488079e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page