disklru


Namedisklru JSON
Version 2.0.4 PyPI version JSON
download
home_pagehttps://github.com/zackees/disklru
SummaryNone
upload_time2024-12-12 10:15:49
maintainerZachary Vorhies
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/zackees/disklru/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/lint.yml)

[![MacOS_Tests](https://github.com/zackees/disklru/actions/workflows/push_macos.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/push_macos.yml)
[![Ubuntu_Tests](https://github.com/zackees/disklru/actions/workflows/push_ubuntu.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/push_ubuntu.yml)
[![Win_Tests](https://github.com/zackees/disklru/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/push_win.yml)


# Usage

```python
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

```python
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:

```bash
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_size` is now `max_entries`
  * 2.0.0 - Overhaul - now allows multithreaded access, connection pool, get/put bytes. purge() now takes in a timestamp aware value for purging.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zackees/disklru",
    "name": "disklru",
    "maintainer": "Zachary Vorhies",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/83/20/d563e0f1864d2031c6030489c28741de2bc857c4129ade15ead10613f1f9/disklru-2.0.4.tar.gz",
    "platform": null,
    "description": "# disklru\r\n\r\n`pip install disklru`\r\n\r\nCreates a disk based lru (least recently used) cache, backed by sqlite, that you can use in your apps.\r\n\r\nZero dependency package. Only relies on the python standard lib. Cross platform tests.\r\n\r\n[![Linting](https://github.com/zackees/disklru/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/lint.yml)\r\n\r\n[![MacOS_Tests](https://github.com/zackees/disklru/actions/workflows/push_macos.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/push_macos.yml)\r\n[![Ubuntu_Tests](https://github.com/zackees/disklru/actions/workflows/push_ubuntu.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/push_ubuntu.yml)\r\n[![Win_Tests](https://github.com/zackees/disklru/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/push_win.yml)\r\n\r\n\r\n# Usage\r\n\r\n```python\r\nfrom disklru import DiskLRUCache\r\n\r\nLRU_CACHE_FILE = \"cache.db\"\r\nMAX_ENTRIES = 4\r\ncache = DiskLRUCache(LRU_CACHE_FILE, MAX_ENTRIES)\r\ncache.put(\"key\", \"value\")\r\nassert cache.get(\"key1\") == \"val\"\r\ncache.clear()\r\n```\r\n\r\n# API\r\n\r\n```python\r\nclass DiskLRUCache:\r\n    \"\"\"Disk-based LRU cache using SQLite.\"\"\"\r\n\r\n    def get(self, key: str) -> str | None:\r\n        \"\"\"Returns the value associated with the given key, or None if the key is not in the cache.\"\"\"\r\n\r\n    def compare_and_swap(self, key: str, prev_val: str, new_val: str) -> tuple[bool, str | None]:\r\n        \"\"\"Performs compare and swap\"\"\"\r\n\r\n    def get_bytes(self, key: str) -> bytes | None:\r\n        \"\"\"Returns the bytes values associated with the given key\"\"\"\r\n\r\n    def get_json(self, key: str) -> Any:\r\n        \"\"\"Returns the value associated with the given key, or None if the key is not in the cache.\"\"\"\r\n\r\n    def put(self, key: str, value: str) -> None:\r\n        \"\"\"Sets the value associated with the given key.\"\"\"\r\n\r\n    def put_bytes(self, key: str, value: bytes) ->: None:\r\n        \"\"\"Sets the byte value associated with the given key.\"\"\"\r\n\r\n    def put_json(self, key: str, val: Any) -> None:\r\n        \"\"\"Sets the value associated with the given key.\"\"\"\r\n\r\n    def delete(self, key) -> None:\r\n        \"\"\"Deletes the given key from the cache.\"\"\"\r\n\r\n    def purge(self, timestamp) -> None:\r\n        \"\"\"Purges all elements less than the timestamp.\"\"\"\r\n\r\n    def clear(self) -> None:\r\n        \"\"\"Clears the cache.\"\"\"\r\n\r\n    def __del__(self) -> None:\r\n        \"\"\"Destructor.\"\"\"\r\n        self.close()\r\n\r\n    def close(self) -> None:\r\n        \"\"\"Closes the connection to the database.\"\"\"\r\n```\r\n\r\n# Development\r\n\r\nFirst install development dependencies:\r\n\r\n```bash\r\npip install -e \".[dev]\"\r\n```\r\n\r\n### Windows\r\n\r\nThis environment requires you to use `git-bash`.\r\n\r\n### Linting\r\n\r\nRun `./lint.sh` to find linting errors using `pylint`, `flake8`, `mypy` and other tools.\r\n\r\n\r\n### Releases\r\n\r\n  * 2.0.3 - Added `compare_and_swap()` for atomic swapping of strings.\r\n  * 2.0.2 - __contains__ operator is now defined so that you can do \"key\" in disklur\r\n  * 2.0.1 - `max_size` is now `max_entries`\r\n  * 2.0.0 - Overhaul - now allows multithreaded access, connection pool, get/put bytes. purge() now takes in a timestamp aware value for purging.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "2.0.4",
    "project_urls": {
        "Homepage": "https://github.com/zackees/disklru"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1f1ffdee839e155305a2a3bf3fb2c0e8d4fbe31666252c3a6aa1e9f0abec75b",
                "md5": "3e1b311b6ad513d261cb9cbb05ef3ce5",
                "sha256": "4a8dd2790778e01cc54fce7d902abd6c8636aee60493054fe6078c38867ca2c2"
            },
            "downloads": -1,
            "filename": "disklru-2.0.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e1b311b6ad513d261cb9cbb05ef3ce5",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 6539,
            "upload_time": "2024-12-12T10:15:47",
            "upload_time_iso_8601": "2024-12-12T10:15:47.168643Z",
            "url": "https://files.pythonhosted.org/packages/a1/f1/ffdee839e155305a2a3bf3fb2c0e8d4fbe31666252c3a6aa1e9f0abec75b/disklru-2.0.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8320d563e0f1864d2031c6030489c28741de2bc857c4129ade15ead10613f1f9",
                "md5": "c6a01ff5c023f012cc9c5b3012f205e2",
                "sha256": "5715e38bfbee01b7b3f58a8b55cdbcbef53164b42b0e1d950e8d51a6e7ef9dd5"
            },
            "downloads": -1,
            "filename": "disklru-2.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "c6a01ff5c023f012cc9c5b3012f205e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12949,
            "upload_time": "2024-12-12T10:15:49",
            "upload_time_iso_8601": "2024-12-12T10:15:49.379764Z",
            "url": "https://files.pythonhosted.org/packages/83/20/d563e0f1864d2031c6030489c28741de2bc857c4129ade15ead10613f1f9/disklru-2.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-12 10:15:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zackees",
    "github_project": "disklru",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "disklru"
}
        
Elapsed time: 3.93410s