fastapi-easy-cache


Namefastapi-easy-cache JSON
Version 1.0.2 PyPI version JSON
download
home_page
Summary
upload_time2024-01-05 12:10:37
maintainer
docs_urlNone
authorDrEgg
requires_python>=3.11,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Fastapi easy cache

<hr>
An easy to use tool for caching fastapi returnings using sqlite as backend

### When should I use fastapi-easy-cache?
1. Returning json serializable data
2. Using GET method
3. Returning dynamic but repeated data (like data refresh everyday)
4. Don't have complicated requirements and too lazy to build a tool yourself

### When should I NOT use fastapi-easy-cache?
1. Returning not json serializable data (bytes, datetime, etc)
2. Using POST method
3. Returning frequently changing data (like data refresh every second)
4. Need advanced features (recommend: [fastapi-cache](https://github.com/long2ice/fastapi-cache))

<hr>

## Installation
We recommend you have fastapi installed
```shell
pip install fastapi-easy-cache
```

## Usage

### Initializing

The following code will
1. create a sqlite database in **dbPath**
2. sotore cache in filesystem
```python
import fastapi_easy_cache

fastapi_easy_cache.apiCache(db_path='./temp/cache', in_memory=False)
```
#### args
db_path: path to sqlite database
in_memory: set up cache in memory, db_path will be database name when set to True


### Using
You just need to add `@cache(expire=20)` under fastapi route decorator, add flil in expire time and it's all done.

`expire` is counted in second

```python
from fastapi_easy_cache import cache

@app.get('/testCache/{path}')
@cache(expire=20)
def test(path):
    data = path
    return data
```

With GET route with arguments, you must add request: Request to your function
```python
from starlette.requests import Request
from fastapi_easy_cache import cache

@app.get('/testCacheWithArg/{path}')
@cache(expire=20)
def testArg(path, arg1, arg2, request: Request):
    data = {'path': path,
         'arg1': arg1,
         'arg2': arg2}
    return data
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fastapi-easy-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "DrEgg",
    "author_email": "dev@dregg.me",
    "download_url": "https://files.pythonhosted.org/packages/d8/a1/f031b66c98753d97a668bfb9ec9286e89cf66c20e9944678896facbc251a/fastapi_easy_cache-1.0.2.tar.gz",
    "platform": null,
    "description": "# Fastapi easy cache\n\n<hr>\nAn easy to use tool for caching fastapi returnings using sqlite as backend\n\n### When should I use fastapi-easy-cache?\n1. Returning json serializable data\n2. Using GET method\n3. Returning dynamic but repeated data (like data refresh everyday)\n4. Don't have complicated requirements and too lazy to build a tool yourself\n\n### When should I NOT use fastapi-easy-cache?\n1. Returning not json serializable data (bytes, datetime, etc)\n2. Using POST method\n3. Returning frequently changing data (like data refresh every second)\n4. Need advanced features (recommend: [fastapi-cache](https://github.com/long2ice/fastapi-cache))\n\n<hr>\n\n## Installation\nWe recommend you have fastapi installed\n```shell\npip install fastapi-easy-cache\n```\n\n## Usage\n\n### Initializing\n\nThe following code will\n1. create a sqlite database in **dbPath**\n2. sotore cache in filesystem\n```python\nimport fastapi_easy_cache\n\nfastapi_easy_cache.apiCache(db_path='./temp/cache', in_memory=False)\n```\n#### args\ndb_path: path to sqlite database\nin_memory: set up cache in memory, db_path will be database name when set to True\n\n\n### Using\nYou just need to add `@cache(expire=20)` under fastapi route decorator, add flil in expire time and it's all done.\n\n`expire` is counted in second\n\n```python\nfrom fastapi_easy_cache import cache\n\n@app.get('/testCache/{path}')\n@cache(expire=20)\ndef test(path):\n    data = path\n    return data\n```\n\nWith GET route with arguments, you must add request: Request to your function\n```python\nfrom starlette.requests import Request\nfrom fastapi_easy_cache import cache\n\n@app.get('/testCacheWithArg/{path}')\n@cache(expire=20)\ndef testArg(path, arg1, arg2, request: Request):\n    data = {'path': path,\n         'arg1': arg1,\n         'arg2': arg2}\n    return data\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "1.0.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d23d8b54fe0c69b1b4be77ff1bba8acdf2805e93e394505b3894c3c72483c581",
                "md5": "57fd162017336b8b990df962582a2c2a",
                "sha256": "9238db84dcfe58b0f8c24fc5ee8fa023e4b4f7cccf1059aedd49a87c7386ab40"
            },
            "downloads": -1,
            "filename": "fastapi_easy_cache-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "57fd162017336b8b990df962582a2c2a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 3508,
            "upload_time": "2024-01-05T12:10:36",
            "upload_time_iso_8601": "2024-01-05T12:10:36.193638Z",
            "url": "https://files.pythonhosted.org/packages/d2/3d/8b54fe0c69b1b4be77ff1bba8acdf2805e93e394505b3894c3c72483c581/fastapi_easy_cache-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8a1f031b66c98753d97a668bfb9ec9286e89cf66c20e9944678896facbc251a",
                "md5": "d212e25002185859dbcb8801b4e0847f",
                "sha256": "77a28eba4a4e849fdd5640b305c09827106993e5c329d4a1a1725d1837690262"
            },
            "downloads": -1,
            "filename": "fastapi_easy_cache-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d212e25002185859dbcb8801b4e0847f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11,<4.0",
            "size": 2847,
            "upload_time": "2024-01-05T12:10:37",
            "upload_time_iso_8601": "2024-01-05T12:10:37.381325Z",
            "url": "https://files.pythonhosted.org/packages/d8/a1/f031b66c98753d97a668bfb9ec9286e89cf66c20e9944678896facbc251a/fastapi_easy_cache-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-05 12:10:37",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fastapi-easy-cache"
}
        
Elapsed time: 0.15669s