An asyncio Cache
Project description
utic-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.1.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.1.tar.gz.
File metadata
- Download URL: utic_cache-2.2.1.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 |
cf154843628b7db0e8b655ffad5d36d087e9442dcda39d0e8d3ba5b3fcf99c88
|
|
| MD5 |
660be3c01269e1365fa4e7a86a779c1d
|
|
| BLAKE2b-256 |
3f1486a5f5acb413fa38f9e12419c691141fa3464c0793a1972cd2fca9aaa62b
|
File details
Details for the file utic_cache-2.2.1-py3-none-any.whl.
File metadata
- Download URL: utic_cache-2.2.1-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 |
2a23379c2548a6c5d2304093e7ef0464ecf0ae6979fa5abfe4dd5a0a6605dfba
|
|
| MD5 |
92b16965e917d9fa8e3e07949ff79085
|
|
| BLAKE2b-256 |
ca1118b0ae87f5f735344cf50b998f9eaec0356822b8da2a9e17927e237ab431
|