An asyncio Cache
Project description
async-cache
A caching solution for asyncio. Heavily changed fork of async-cache package.
Installation
pip install utic-cache
Basic Usage
# LRU Cache
from cache import Cached, LRU
@Cached(LRU(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 Cached, TTL
@Cached(TTL(ttl=60, maxsize=1024), skip_args=1)
async def func(*args, **kwargs):
"""
time_to_live: max time for which a cached result is valid (in seconds)
maxsize: max number of results that are cached.
if max limit is reached the oldest result is deleted.
skip_args: Use `1` to skip first arg of func in determining cache key
"""
pass
# Supports primitive as well as non-primitive function parameter.
# Currently TTL & LRU cache is supported.
Advanced Usage
from cache import Cached, LRU
class CustomDataClass:
id: int
value: int
@Cached(LRU(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.
# To refresh the function result use the `use_cache=False` param in the function invocation
func(*args, use_cache=False, **kwargs)
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
utic_cache-2.2.0.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file utic_cache-2.2.0.tar.gz.
File metadata
- Download URL: utic_cache-2.2.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.10.5 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
621cd8cdb964de26b26736c194228538e10bf76b0732acd857e2ad6663ea72a7
|
|
| MD5 |
7fcd54504df40b3ebe6dc80e7a70bcd9
|
|
| BLAKE2b-256 |
e1bacf3633e82d6a4b97aace90d2c956be45e7e1558d9a9b72f62df39148a3fb
|
File details
Details for the file utic_cache-2.2.0-py3-none-any.whl.
File metadata
- Download URL: utic_cache-2.2.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.10.5 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
068f162193e9568c17632ca68e14111911bebd0283f63d96fcd233e8d09f77ed
|
|
| MD5 |
316885959d1fd3838797503453c49f27
|
|
| BLAKE2b-256 |
08c8386f044385db15b85fc167b704c3a8ec1956ccb5bdb5d3384054d35b9869
|