Creates a python disk LRU / cache - great for apps that want to save data
Project description
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 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_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
Windows
This environment requires you to use git-bash
.
Linting
Run ./lint.sh
to find linting errors using pylint
, flake8
and mypy
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
disklru-1.0.7.tar.gz
(10.2 kB
view hashes)
Built Distribution
Close
Hashes for disklru-1.0.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc37b3576a903cf24605bcf231925d4eeb9753c275156db1b9abe977c9931dab |
|
MD5 | 73f6e5d8c34285ec898ad010e05c1e7e |
|
BLAKE2b-256 | ad60c89766ae48bc2ff15e2715fd9c532fa506358b3b5605115879f838ead077 |