No project description provided
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_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.1 -
max_size
is 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
disklru-2.0.1.tar.gz
(11.0 kB
view details)
Built Distribution
File details
Details for the file disklru-2.0.1.tar.gz
.
File metadata
- Download URL: disklru-2.0.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 717466361d0696309284f6732196090fc522912f80382dab49c230ec8cdfcecf |
|
MD5 | 644f1683e6f8482fe55a7069a75ce299 |
|
BLAKE2b-256 | c15d9eb4284192ce8dffff4a4bd3688bd2e5bbd4bae9018410d925ffff007cbf |
File details
Details for the file disklru-2.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: disklru-2.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d09a4e598fb69ffbe649bade02b9ac58b358eaf34dc7b873e64a37ad882d47eb |
|
MD5 | 99d6fa4f0b4cffc58947b63ecf8f8507 |
|
BLAKE2b-256 | bd6f3e5cb3b3c4eb3315af1a0bda5e61395c30e2aa8f5bc9622b56ac747e805a |