Skip to main content

FastAPI simple cache

Project description

FastAPI Cache Plus

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.1.0.tar.gz (72.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.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastapi_cache_plus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 088d0a96245cdd231a9c07e67bd8ba8d90e1161a8388f46c58d03b01d66fb288
MD5 cf445d9284673b8150f1b17d6a449df3
BLAKE2b-256 97e9b60feceba0cbddd7f5a2c6178c288f4a4de81d3cc85d01ddb37e772fa940

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_cache_plus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cb58420fd319b61919aca6f308d26a735ae87d2c4892186062c710d69a2cd0e
MD5 4151e41243240e96dd7af2e6be86597e
BLAKE2b-256 a7ec4219d590e3620a2af90f07669246471aeca7f405614c7db4bd27b3c0d30b

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