Skip to main content

Yet another Python cache library

Project description

cachepot

image image CircleCI

Yet another Python cache library. This has Python 3 typing hints.

Installation

$ pip install cachepot

Usage

>>> from cachepot.store import CacheStore
>>> from cachepot.backend.filesystem import FileSystemCacheBackend
>>> from cachepot.serializer.pickle import PickleSerializer
>>> store = CacheStore(
...     namespace='testing',
...     key_serializer=PickleSerializer(),
...     value_serializer=PickleSerializer(),
...     backend=FileSystemCacheBackend('/tmp'),
...     default_expire_seconds=3600,
... )
>>> store.put({'some': 'key'}, {'some': 'value'})
>>> store.get({'some': 'key'})
{'some': 'value'}
>>> store.put({'some': 'short expiring key'}, {'some': 'value'}, expire_seconds=10)

Proxy interface

result = store.proxy(some_func)(some_args)

is same as

result = store.get(some_arg)
if result is None:
    result = some_func(some_args)
    store.set(result)

In short, this works as proxy. This helps to make codes straight forward. proxy method can be passed two arguments cache_key and expire_seconds.

Core Idea

  • Typing supports
  • Generic serializers ... pickle, JSON, and more serializers you can define.
  • Generic backends ... Currently supports only filesystem backend and sqlite3 backend. But it is not so difficult to add Redis or the other KVS backends. And of course you can define own backend.
  • Proxy interface

Development

You can install requirements with pipenv

$ pipenv install --dev

Test

$ flake8
$ mypy .
$ python3 -m unittest discover

LICENSE

The 3-Clause BSD License. See also LICENSE file.

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

cachepot-0.1.3.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

cachepot-0.1.3-py3-none-any.whl (8.4 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