██████╗ █████╗ ██████╗██╗ ██╗██████╗
██╔════╝██╔══██╗██╔════╝██║ ██║██╔══██╗
██║ ███████║██║ ███████║██████╔╝
██║ ██╔══██║██║ ██╔══██║██╔══██╗
╚██████╗██║ ██║╚██████╗██║ ██║██║ ██║
╚═════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝
cachr: superfast, composable caching for Python
cachr is a Python package that provides superfast, composable caches designed to optimize your applications in an easy and intuitive way. It aims to be the go-to package to use and build caches that make your applications superfast, memory-efficient and user-friendly.
pip install cachr
Table of Contents
- Main Features
- Usage Example
- Installation
- Dependencies
- License
- Documentation
- Development
- Contributing to Cachr
Main Features
- 🐍 Pure Python
- 🖌 Easily extendable
- 👨🎨 User-friendly
Usage Example
At the moment there are five caches available for use:
- LFUCache: Removes the least frequently used item in the cache when it overflows
- LRUCache: A Least Recently Used Cache removes the least recently used item when it overflows
- RandomReplaceCache: randomly expells an item from the cache when it overflows
- TTLCache: A Time-To-Live-cache acts like a LRUCache and also removes an entry from the cache after a certain expiration time
- SlidingWindowCache: Like a TTLCache but it renews the expiration date eacht time an item is requested from the cache.
All caches are added to your code in two ways: by decorator or as a regular object.
Decorator:
import time
from cachr import LRUCache
# 1. Decorate your function
@LRUCache(capacity=2)
def add(i, y):
time.sleep(1)
print("adding..")
return i + y
print(add(1, 2)) # <-- takes a second to calculate
print(add(1, 2)) # <-- takes value from cache immediately
print(add(1, 2)) # <-- takes value from cache immediately
Object:
from cachr import TTLCache
my_cache = TTLCache(capacity=25, ttl_seconds=60)
def very_expensive_function(number:int) -> int:
return number * number
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5, 7, 9, 1, 1, 1, 1]:
value_from_cache = my_cache.get(i)
if value_from_cache is not None:
print(f"Answer for {i} is {value_from_cache}")
continue
print(f"calculating expensive function for {i}..")
my_cache.put(key=i, value=very_expensive_function(number=i))
Installation
pip install cachr
The source code is currently hosted on GitHub at: https://github.com/mike-huls/cachr
Binary installers for the latest released version are available at the Python Package Index (PyPI).
Dependencies
Cachr has no Python dependencies
License
Documentation
🔨 Under construction
Development
Find the changelog and list of upcoming features here.
Contributions are always welcome; feel free to submit bug reports, bug fixes, feature requests, documentation improvements or enhancements!
Metadata
Release files for cachr 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cachr-0.0.9.tar.gz | 13.3 kB | Without provenance | Details for cachr-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cachr-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for cachr-0.0.9-py3-none-any.whl |
Total release size: 23.3 kB
Release files / cachr-0.0.9.tar.gz
| Download URL | cachr-0.0.9.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2896ab8c10a703a8fb6d2ea41b46ec57d8a6421ca5ee2e6e8bb8ae69f0297a5
|
|
BLAKE2b-256 checksum How to use checksums |
e9c7db17bd94de790f37e2de9d7e76628c76753d9c35d798518a8e59cd3527c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.4.29
|
Release files / cachr-0.0.9-py3-none-any.whl
| Download URL | cachr-0.0.9-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e646613a7a005363f4a2d30026fcb8988fd8f0ed0464b2a0bbaafee4ccd6df22
|
|
BLAKE2b-256 checksum How to use checksums |
0b57909ef2f75016266b56548bea92eb94b28f0263a2a8026714502e98a91acc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.4.29
|
Security for cachr 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.