No project description provided
Project description
Py-Cachify
py-cachify is a library that provides small but useful cache utilities.
Some parts were heavily inspired by douglasfarinelli's python-cachelock lib, which is sadly no longer maintained.
py-cachify works well in both sync and async environments, has 100% test coverage, is backend agnostic (you can provide your own client as long as it matches the signature), and supports Python from 3.8 and upward.
It offers distributed (cache based) locks and decorators for securing function executions and storing their results in the cache.
Table of Contents
Documentation
Detailed documentation can be found at https://py-cachify.readthedocs.io/en/latest/.
Installation
To install:
pip install py-cachify
# or if using poetry
poetry add py-cachify
Examples
To start working with it, you'll have to initialize it using init_cachify
:
from py_cachify import init_cachify
init_cachify()
By default, it will use an in-memory cache.
If you want to use Redis:
from py_cachify import init_cachify
from redis.asyncio import from_url as async_from_url
from redis import from_url
init_cachify(sync_client=from_url(redis_url), async_client=async_from_url(async_redis_client))
Normally you wouldn't have to use both sync and async clients since an application usually works in a single mode i.e. sync/async.
Once initialized you can use everything that the library provides straight up without being worried about managing the cache yourself.
If you forgot to call init_cachify
the CachifyInitError
will be raised during runtime.
from py_cachify import once
# Make sure there is just one copy of a function running at a time
@once(key='long_running_function')
async def long_running_function() -> str:
# Executing long-running operation...
pass
For more detailed documentation and examples please visit https://py-cachify.readthedocs.io/en/latest/.
Contributing
If you'd like to contribute, please first discuss the changes using Issues, and then don't hesitate to shoot a PR which will be reviewed shortly.
License
This project is licensed under the MIT License - see the 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
Built Distribution
Hashes for py_cachify-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2226d26e31d57429814ea740b1ebbfd02aa6670f705c54022ce3116287049a53 |
|
MD5 | 792d726580433cbd239fd22121f6190e |
|
BLAKE2b-256 | 63dc6b9404e3e9a881c9e65ef2346f11360db3df7bfbbbc0448cd48e8cbb4f63 |