Skip to main content

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

Release files for fastapi-easy-cache 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-easy-cache 1.0.2
File Size Uploaded
fastapi_easy_cache-1.0.2.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-easy-cache 1.0.2
File Interpreter ABI Platform
fastapi_easy_cache-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / fastapi_easy_cache-1.0.2.tar.gz

Download URL fastapi_easy_cache-1.0.2.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
77a28eba4a4e849fdd5640b305c09827106993e5c329d4a1a1725d1837690262
BLAKE2b-256 checksum
How to use checksums
d8a1f031b66c98753d97a668bfb9ec9286e89cf66c20e9944678896facbc251a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0

Release files / fastapi_easy_cache-1.0.2-py3-none-any.whl

Download URL fastapi_easy_cache-1.0.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9238db84dcfe58b0f8c24fc5ee8fa023e4b4f7cccf1059aedd49a87c7386ab40
BLAKE2b-256 checksum
How to use checksums
d23d8b54fe0c69b1b4be77ff1bba8acdf2805e93e394505b3894c3c72483c581
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page