fastapi-cache-plus


Namefastapi-cache-plus JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryFastAPI simple cache
upload_time2025-01-26 00:24:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseNone
keywords aioredis asyncio cache fastapi redis starlette
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI Cache Plus

![Static Badge](https://img.shields.io/badge/FastAPI%20Cache-Successor-blue) ![GitHub License](https://img.shields.io/github/license/leynier/fastapi-cache-plus?label=License) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/leynier/fastapi-cache-plus/tests.yaml?label=Tests) [![codecov](https://codecov.io/github/leynier/fastapi-cache-plus/branch/master/graph/badge.svg?token=EGBM54K25J)](https://codecov.io/github/leynier/fastapi-cache-plus) ![PyPI - Version](https://img.shields.io/pypi/v/fastapi-cache-plus?label=Version)

> This project is a continuation of the project [fastapi_cache](https://github.com/comeuplater/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

```sh
pip install fastapi-cache-plus
```

## Usage example

```python
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()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastapi-cache-plus",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "aioredis, asyncio, cache, fastapi, redis, starlette",
    "author": null,
    "author_email": "Leynier Guti\u00e9rrez Gonz\u00e1lez <leynier41@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/84/ca/44243c7bdcc017c2d52397c0ad6fc8330695d8609d06e00175e29f99c4ea/fastapi_cache_plus-0.2.0.tar.gz",
    "platform": null,
    "description": "# FastAPI Cache Plus\n\n![Static Badge](https://img.shields.io/badge/FastAPI%20Cache-Successor-blue) ![GitHub License](https://img.shields.io/github/license/leynier/fastapi-cache-plus?label=License) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/leynier/fastapi-cache-plus/tests.yaml?label=Tests) [![codecov](https://codecov.io/github/leynier/fastapi-cache-plus/branch/master/graph/badge.svg?token=EGBM54K25J)](https://codecov.io/github/leynier/fastapi-cache-plus) ![PyPI - Version](https://img.shields.io/pypi/v/fastapi-cache-plus?label=Version)\n\n> This project is a continuation of the project [fastapi_cache](https://github.com/comeuplater/fastapi_cache). Many thanks to Ivan Sushkov (the original author) for their work and contributions.\n\nImplements simple lightweight cache system as dependencies in FastAPI.\n\n## Installation\n\n```sh\npip install fastapi-cache-plus\n```\n\n## Usage example\n\n```python\nfrom fastapi import Depends, FastAPI\n\nfrom fastapi_cache_plus import caches, close_caches\nfrom fastapi_cache_plus.backends.redis import CACHE_KEY, RedisCacheBackend\n\napp = FastAPI()\n\n\ndef redis_cache():\n    return caches.get(CACHE_KEY)\n\n\n@app.get(\"/\")\nasync def hello(cache: RedisCacheBackend = Depends(redis_cache)):\n    in_cache = await cache.get(\"some_cached_key\")\n    if not in_cache:\n        await cache.set(\"some_cached_key\", \"new_value\", 5)\n\n    return {\"response\": in_cache or \"default\"}\n\n\n@app.on_event(\"startup\")\nasync def on_startup() -> None:\n    rc = RedisCacheBackend(\"redis://redis\")\n    caches.set(CACHE_KEY, rc)\n\n\n@app.on_event(\"shutdown\")\nasync def on_shutdown() -> None:\n    await close_caches()\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "FastAPI simple cache",
    "version": "0.2.0",
    "project_urls": {
        "Changelog": "https://github.com/leynier/fastapi-cache-plus/blob/master/changelog.md",
        "Homepage": "https://github.com/leynier/fastapi-cache-plus",
        "Issues": "https://github.com/leynier/fastapi-cache-plus/issues",
        "Repository": "https://github.com/leynier/fastapi-cache-plus"
    },
    "split_keywords": [
        "aioredis",
        " asyncio",
        " cache",
        " fastapi",
        " redis",
        " starlette"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7e7ec5831ceae4f950547b336b579900682b66e519ede23a97df7577488079e4",
                "md5": "ff147b0764c56576e245403204db10e8",
                "sha256": "0a3f243eab144650e86b4d1d28e3234f2ffc4289d21504b04dc9ed6aa399cc1d"
            },
            "downloads": -1,
            "filename": "fastapi_cache_plus-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ff147b0764c56576e245403204db10e8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6134,
            "upload_time": "2025-01-26T00:24:53",
            "upload_time_iso_8601": "2025-01-26T00:24:53.168390Z",
            "url": "https://files.pythonhosted.org/packages/7e/7e/c5831ceae4f950547b336b579900682b66e519ede23a97df7577488079e4/fastapi_cache_plus-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "84ca44243c7bdcc017c2d52397c0ad6fc8330695d8609d06e00175e29f99c4ea",
                "md5": "fa18c8fe6239c3d53c36ee3c5d0cae30",
                "sha256": "526241a2340a8ecf1ecedefab480da8aec128c4c17d32397d6617d49d6094f81"
            },
            "downloads": -1,
            "filename": "fastapi_cache_plus-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fa18c8fe6239c3d53c36ee3c5d0cae30",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 74478,
            "upload_time": "2025-01-26T00:24:54",
            "upload_time_iso_8601": "2025-01-26T00:24:54.810365Z",
            "url": "https://files.pythonhosted.org/packages/84/ca/44243c7bdcc017c2d52397c0ad6fc8330695d8609d06e00175e29f99c4ea/fastapi_cache_plus-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-26 00:24:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "leynier",
    "github_project": "fastapi-cache-plus",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastapi-cache-plus"
}
        
Elapsed time: 2.42468s