Yet another Python cache library
Project description
cachepot
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 method
result = store.proxy(some_func)(some_args)
is the equivalent of
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
Serializers convert python objects into bytes. Backends save/load bytes. So serializers and backends are independent. CacheStore is the facade of them.
- Python3 typing supports
- namespaces
- Proxy method
Features
Serializers
- str ... cachepot.serializer.str.StringSerializer
- pickle ... cachepot.serializer.pickle.PickleSerializer
- JSON ... cachepot.serializer.json.JSONSerializer
And more serializers you can define.
Backends
- Save to files ... cachepot.backend.filesystem.FileSystemCacheBackend
- Save to SQLite3 DB records ... cachepot.backend.sqlite.SQLiteCacheBackend
- Save to Redis DB ... cachepot.backend.redis.RedisCacheBackend
Of course you can define own backend.
Development
You can install requirements with poetry.
$ poetry install
Test
$ poetry poe check # lint and type check
$ poetry poe test # run tests
LICENSE
The 3-Clause BSD License. See also LICENSE file.
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
cachepot-0.4.0.tar.gz
(33.1 kB
view hashes)
Built Distribution
cachepot-0.4.0-py3-none-any.whl
(13.5 kB
view hashes)