Skip to main content

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.

Linting

MacOS_Tests Ubuntu_Tests Win_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.0 - Overhaul - now allows multithreaded access, connection pool, get/put bytes. purge() now takes in a timestamp aware value for purging.

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-2.0.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

disklru-2.0.0-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file disklru-2.0.0.tar.gz.

File metadata

  • Download URL: disklru-2.0.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for disklru-2.0.0.tar.gz
Algorithm Hash digest
SHA256 74ad294b10fc9b095a4838f5c2dd688257546ccdd051b1d1794bbbc1f40c02bf
MD5 ca783a08eab6646ea0fa55f6cb5fdbc8
BLAKE2b-256 2e3ce2ed99c79e0a882e4b6cc161407a70d7fbb006bacf5a8900e8fa2733c6b9

See more details on using hashes here.

File details

Details for the file disklru-2.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: disklru-2.0.0-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

Hashes for disklru-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1a0a4711cba154a08af094b063d141b3b1a735d6341fe3f1288a75782c3a5989
MD5 9409186ba34e050cd65c2a80650b67df
BLAKE2b-256 905d0daeb8ed3d1bec4fc3151e5615b91a72ec8a86d92051aced9887e416d91a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page