disklru
pip install disklru
Creates a disk based lru (least recently used) cache, backed by sqlite, that you can use in your apps.
Zero dependency package. Only relies on the python standard lib. Cross platform tests.
Usage
from disklru import DiskLRUCache
LRU_CACHE_FILE = "cache.db"
MAX_ENTRIES = 4
cache = DiskLRUCache(LRU_CACHE_FILE, MAX_ENTRIES)
cache.put("key", "value")
assert cache.get("key1") == "val"
cache.clear()
API
class DiskLRUCache:
"""Disk-based LRU cache using SQLite."""
def get(self, key: str) -> str | None:
"""Returns the value associated with the given key, or None if the key is not in the cache."""
def compare_and_swap(self, key: str, prev_val: str, new_val: str) -> tuple[bool, str | None]:
"""Performs compare and swap"""
def get_bytes(self, key: str) -> bytes | None:
"""Returns the bytes values associated with the given key"""
def get_json(self, key: str) -> Any:
"""Returns the value associated with the given key, or None if the key is not in the cache."""
def put(self, key: str, value: str) -> None:
"""Sets the value associated with the given key."""
def put_bytes(self, key: str, value: bytes) ->: None:
"""Sets the byte value associated with the given key."""
def put_json(self, key: str, val: Any) -> None:
"""Sets the value associated with the given key."""
def delete(self, key) -> None:
"""Deletes the given key from the cache."""
def purge(self, timestamp) -> None:
"""Purges all elements less than the timestamp."""
def clear(self) -> None:
"""Clears the cache."""
def __del__(self) -> None:
"""Destructor."""
self.close()
def close(self) -> None:
"""Closes the connection to the database."""
Development
First install development dependencies:
pip install -e ".[dev]"
Windows
This environment requires you to use git-bash.
Linting
Run ./lint.sh to find linting errors using pylint, flake8, mypy and other tools.
Releases
- 2.0.3 - Added
compare_and_swap()for atomic swapping of strings. - 2.0.2 - contains operator is now defined so that you can do "key" in disklur
- 2.0.1 -
max_sizeis nowmax_entries - 2.0.0 - Overhaul - now allows multithreaded access, connection pool, get/put bytes. purge() now takes in a timestamp aware value for purging.
Metadata
Release files for disklru 2.0.4
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 |
|---|---|---|---|---|
| disklru-2.0.4.tar.gz | 12.9 kB | Without provenance | Details for disklru-2.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| disklru-2.0.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for disklru-2.0.4-py2.py3-none-any.whl |
Total release size: 19.5 kB
Release files / disklru-2.0.4.tar.gz
| Download URL | disklru-2.0.4.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5715e38bfbee01b7b3f58a8b55cdbcbef53164b42b0e1d950e8d51a6e7ef9dd5
|
|
BLAKE2b-256 checksum How to use checksums |
8320d563e0f1864d2031c6030489c28741de2bc857c4129ade15ead10613f1f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.5
|
Release files / disklru-2.0.4-py2.py3-none-any.whl
| Download URL | disklru-2.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
4a8dd2790778e01cc54fce7d902abd6c8636aee60493054fe6078c38867ca2c2
|
|
BLAKE2b-256 checksum How to use checksums |
a1f1ffdee839e155305a2a3bf3fb2c0e8d4fbe31666252c3a6aa1e9f0abec75b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.5
|
Security for disklru 2.0.4
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.