An asyncio Cache
Project description
- info:
A caching solution for asyncio
Installation
pip install async-cache
Basic Usage
# LRU Cache
from cache import AsyncLRU
@AsyncLRU(maxsize=128)
async def func(*args, **kwargs):
"""
maxsize : max number of results that are cached.
if max limit is reached the oldest result is deleted.
"""
pass
# TTL Cache
from cache import AsyncTTL
@AsyncTTL(time_to_live=60, maxsize=1024)
async def func(*args, **kwargs):
"""
time_to_live : max time for which a cached result is valid
maxsize : max number of results that are cached.
if max limit is reached the oldest result is deleted.
"""
pass
# Supports primitive as well as non-primitive function parameter.
# Currently TTL & LRU cache is supported.
Advanced Usage
class CustomDataClass:
id: int
value: int
from cache import AsyncLRU
@AsyncLRU(maxsize=128)
async def func(model: "CustomDataClass"):
...
# function logic
...
# async-cache will work even if function parameters are:
# 1. orm objects
# 2. request object
# 3. any other custom object type.
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
async-cache-1.1.1.tar.gz
(3.8 kB
view details)
File details
Details for the file async-cache-1.1.1.tar.gz
.
File metadata
- Download URL: async-cache-1.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81aa9ccd19fb06784aaf30bd5f2043dc0a23fc3e998b93d0c2c17d1af9803393 |
|
MD5 | 1ec882a46cb9524a3bfe3837caf7a29d |
|
BLAKE2b-256 | 736e908402652bf7d8ab02fa204399d9517d247fb3a0926045a8c8a28708cd40 |