https://github.com/mrtj/chainedcache
Simple python cache
https://github.com/mrtj/chainedcache
Last synced: about 1 year ago
JSON representation
Simple python cache
- Host: GitHub
- URL: https://github.com/mrtj/chainedcache
- Owner: mrtj
- License: mit
- Created: 2021-02-11T14:17:31.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-11T17:28:05.000Z (over 5 years ago)
- Last Synced: 2025-01-16T17:30:30.963Z (over 1 year ago)
- Language: Python
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chainedcache
Simple python cache system.
## Installation
```bash
$ python -m pip install git+https://github.com/mrtj/chainedcache
```
## Usage
```python
import json
from chainedcache import DictCache, FileCache, S3Cache, ChainedCache
json2bytes = lambda d: json.dumps(d).encode('UTF-8')
bytes2json = lambda d: json.loads(d.decode('UTF-8'))
stream2json = lambda d: json.load(d)
dict_cache = DictCache()
file_cache = FileCache('./cache', mode='bytes',
put_transformer=json2bytes, get_transformer=bytes2json)
s3_cache = S3Cache('my_s3_bucket', 'cache', region='us-east-1',
put_transformer=json2bytes, get_transformer=stream2json)
cache = ChainedCache([dict_cache, file_cache, s3_cache])
def data_generator(key):
return { "the_key_is": key }
json_data = cache.get_put("hello", data_generator)
```