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.2.tar.gz
(4.6 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.2.tar.gz.
File metadata
- Download URL: utic_cache-2.2.2.tar.gz
- Upload date:
- Size: 4.6 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 |
252dfbd9a422fcb6002cc2610d2513397d5e879e40bacfed63ce3e5de59786b0
|
|
| MD5 |
6b0b488366ab93b6589b8b0487847d83
|
|
| BLAKE2b-256 |
183b4c32d2acfa77836d9bfa4f06c4bbf7908a550de8fbce9290a4322d997fc9
|
File details
Details for the file utic_cache-2.2.2-py3-none-any.whl.
File metadata
- Download URL: utic_cache-2.2.2-py3-none-any.whl
- Upload date:
- Size: 6.8 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 |
f8513017121912b4c42a721493a659551b49a096771d5d2eaabcb4189e48d46a
|
|
| MD5 |
e587e24c5c21ac8b82aee6ce072dce20
|
|
| BLAKE2b-256 |
1c914b19cb8235d7b1f09681f54febee980a64799f31ef369a329e5640f40c12
|