The Simple library for corutine cache
Project description
Description
This is cache for coroutines with a ttl parameter and the auto_refresh
functional.
Explanation
auto_refresh
parameter is needs to call is cached coroutine again
It have been make for coroutines what getting a large data volume from third-party heavy APIs, information from which may change periodically.
Installation
pip install coroutincache
Usage
Simple usage:
import asyncio
from fastapi import FastAPI
from coroutincache import asyncache
from LogSettings import get_logger
logger = get_logger('consolemode')
app = FastAPI()
@asyncache(ttl=20)
async def load_from_api(params=None):
await asyncio.sleep(3)
logger.debug(f'LOAD FROM API')
return [{'namespace': 'A1'}, {'namespace': 'A2'}, {'namespace': 'A3'}]
@app.get("/")
async def root():
result = await load_from_api(32)
logger.info(f'Result: {result}')
return result
Like regular cache with ttl parameter
import asyncio
from coroutincache import asyncache
@asyncache(ttl=20, auto_refresh=False)
async def load_from_api(params=None):
await asyncio.sleep(3)
return [{'namespace': 'A1'}, {'namespace': 'A2'}, {'namespace': 'A3'}] # Large data
License
This project is licensed under the MIT License - see the MIT LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
coroutincache-1.5.0.tar.gz
(3.1 kB
view details)
Built Distribution
File details
Details for the file coroutincache-1.5.0.tar.gz
.
File metadata
- Download URL: coroutincache-1.5.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c91173666ca5e81d581c45aeb9b48aa5f1148f062b6518c8956cb57e036a3380 |
|
MD5 | 88aa66bd204699c23d8636c30170c1a3 |
|
BLAKE2b-256 | 320c90172c00ca9764b44098505a001554fca8c3013e2c90db6cb3d6de28cc20 |
File details
Details for the file coroutincache-1.5.0-py3-none-any.whl
.
File metadata
- Download URL: coroutincache-1.5.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 929ce0b4654f7abbb466262dd4d9699fb629bfcedabba4bf9e93a6548df61c52 |
|
MD5 | 7877b2093530c9091a25562827a264b2 |
|
BLAKE2b-256 | 4b3809efed0f2059755b08f99f148ffaa3d8bb66b77d3f2bccbc19b91216b00a |