| 1 |
# CacheLib |
| 2 |
|
| 3 |
A collection of cache libraries in the same API interface. Extracted from |
| 4 |
Werkzeug. |
| 5 |
|
| 6 |
Supported backends include: |
| 7 |
|
| 8 |
- [DynamoDbCache](./src/cachelib/dynamodb.py) ([DynamoDB](https://aws.amazon.com/dynamodb/)) |
| 9 |
- [FileSystemCache](./src/cachelib/file.py) (file based) |
| 10 |
- [MemcachedCache](./src/cachelib/memcached.py) ([Memcached](https://memcached.org/)) |
| 11 |
- [MongoDbCache](./src/cachelib/mongodb.py) ([MongoDB](https://www.mongodb.com/)) |
| 12 |
- [RedisCache](./src/cachelib/redis.py) ([Redis](https://redis.io/)) |
| 13 |
- [SimpleCache](./src/cachelib/simple.py) (in-memory, single-process) |
| 14 |
- [UWSGICache](./src/cachelib/uwsgi.py) ([uWSGI](https://uwsgi-docs.readthedocs.io/)) |
| 15 |
- [ValkeyCache](./src/cachelib/valkey.py) ([Valkey](https://valkey.io/)) |
| 16 |
|
| 17 |
## Pallets Ecosystem |
| 18 |
|
| 19 |
> [!IMPORTANT]\ |
| 20 |
> This project is part of the Pallets Ecosystem. Pallets is the open source |
| 21 |
> organization that maintains Flask; Pallets-Eco enables community maintenance |
| 22 |
> of related projects. If you are interested in helping maintain this project, |
| 23 |
> please reach out on [the Pallets Discord server][discord]. |
| 24 |
|
| 25 |
[discord]: https://discord.gg/pallets |
| 26 |
|
| 27 |
## Installation |
| 28 |
|
| 29 |
Install from [PyPI]: |
| 30 |
|
| 31 |
```sh |
| 32 |
pip install cachelib |
| 33 |
``` |
| 34 |
|
| 35 |
[PyPI]: https://pypi.org/project/cachelib/ |
| 36 |
|
| 37 |
## A Minimal Example |
| 38 |
|
| 39 |
```python |
| 40 |
from cachelib import SimpleCache |
| 41 |
|
| 42 |
# Create a cache instance |
| 43 |
cache = SimpleCache() |
| 44 |
|
| 45 |
# Set a value in the cache |
| 46 |
cache.set("my_key", "my_value") |
| 47 |
|
| 48 |
# Retrieve the value from the cache |
| 49 |
value = cache.get("my_key") |
| 50 |
print(value) # Output: my_value |
| 51 |
|
| 52 |
# Delete the value from the cache |
| 53 |
cache.delete("my_key") |
| 54 |
|
| 55 |
# Try to retrieve the deleted value |
| 56 |
value = cache.get("my_key") |
| 57 |
print(value) # Output: None |
| 58 |
``` |