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.
Metadata
Release files for cachepot 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cachepot-0.4.0.tar.gz | 33.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cachepot-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.6 kB
Release files / cachepot-0.4.0.tar.gz
| Download URL | cachepot-0.4.0.tar.gz |
|---|---|
| Size | 33.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
690f1f028dd28b1d9fff3dc2c2c7774e1ba2875992014bd9fe41a8613580a124
|
|
BLAKE2b-256 checksum How to use checksums |
fa88db63d9780847639cd52c067ace4823d36466b508b93bb5447b5b47e2cf7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cachepot-0.4.0-py3-none-any.whl
| Download URL | cachepot-0.4.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d0ed4951dad9e50383f4332821b9b58f6f5a5b8fb7338f86549c5ec02c15fb9
|
|
BLAKE2b-256 checksum How to use checksums |
2a890e7fb87cc7ce3b87548fa7617fd8f9e20636d2bcea5b08e9f5d1dc7d85a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|