Skip to main content

This library provides a decorator for caching functions

Project description

Cache Toolz

Maintenance Documentation Status Badge License Number of issues

CI codecov Repo Size

Supported Python versions PyPI version PyBuilder Downloads Per Day PyBuilder Downloads Per Week PyBuilder Downloads Per Month


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


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)

Uploaded Source

Built Distribution

cachetoolz-0.0.1-py3-none-any.whl (15.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page