Skip to main content

No project description provided

Project description

Fastapi easy cache


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)

Installation

We recommend you have fastapi installed

pip install fastapi-easy-cache

Usage

Initializing

The following code will

  1. create a sqlite database in dbPath
  2. sotore cache in filesystem
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

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

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

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_easy_cache-1.0.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

fastapi_easy_cache-1.0.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_easy_cache-1.0.2.tar.gz.

File metadata

  • Download URL: fastapi_easy_cache-1.0.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0

File hashes

Hashes for fastapi_easy_cache-1.0.2.tar.gz
Algorithm Hash digest
SHA256 77a28eba4a4e849fdd5640b305c09827106993e5c329d4a1a1725d1837690262
MD5 d212e25002185859dbcb8801b4e0847f
BLAKE2b-256 d8a1f031b66c98753d97a668bfb9ec9286e89cf66c20e9944678896facbc251a

See more details on using hashes here.

File details

Details for the file fastapi_easy_cache-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_easy_cache-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9238db84dcfe58b0f8c24fc5ee8fa023e4b4f7cccf1059aedd49a87c7386ab40
MD5 57fd162017336b8b990df962582a2c2a
BLAKE2b-256 d23d8b54fe0c69b1b4be77ff1bba8acdf2805e93e394505b3894c3c72483c581

See more details on using hashes here.

Supported by

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