This library provides a decorator for caching functions
Project description
Cache Toolz
Usage
from cachetoolz import cache
# Add cache so you don't always have to access the database, for example
@cache(namespace='todo')
async def get_todos(title=None, status=None):
"""Get all todos filtering by title or status."""
# Clear all caches in all namespaces so that no function has the result lagged to the database for example
@cache.clear(namespaces=['todo'])
async def add_todo(title, status=False):
"""Add todo."""
Remote backends
Redis
from cachetoolz import AsyncRedisBackend, Cache
cache = Cache(AsyncRedisBackend('redis://localhost:6379/0'))
@cache(namespace='todo')
async def get_todos(title=None, status=None):
"""Get all todos filtering by title or status."""
@cache.clear(namespaces=['todo'])
async def add_todo(title, status=False):
"""Add todo."""
Mongo
from cachetoolz import AsyncMongoBackend, Cache
cache = Cache(AsyncMongoBackend('mongodb://username:password@localhost:27017'))
@cache(namespace='todo')
async def get_todos(title=None, status=None):
"""Get all todos filtering by title or status."""
@cache.clear(namespaces=['todo'])
async def add_todo(title, status=False):
"""Add todo."""
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
cachetoolz-0.0.1.tar.gz
(11.4 kB
view hashes)
Built Distribution
cachetoolz-0.0.1-py3-none-any.whl
(15.8 kB
view hashes)
Close
Hashes for cachetoolz-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63d276bbe45170fa15e452f6a2729031b93512b8912965ff0b3af73b0e6487c5 |
|
MD5 | a1d17498b1d4ac95e0779616b2c511d0 |
|
BLAKE2b-256 | f2a42be1ea925348ae134e1a9369769a4e90e7bc13dc951dbb5232d6d3fdb77c |