# 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 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`.
Raw data
{
"_id": null,
"home_page": "https://github.com/zackees/disklru",
"name": "disklru",
"maintainer": "Zachary Vorhies",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "disk lru cache least recently used",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/06/7d/2d05244be999ac4d140020ac5f5b210d50c2f288effacff40dee1ca59b58/disklru-1.0.7.tar.gz",
"platform": null,
"description": "# disklru\n\n`pip install disklru`\n\nCreates a disk based lru (least recently used) cache, backed by sqlite, that you can use in your apps.\n\nZero dependency package. Only relies on the python standard lib. Cross platform tests.\n\n[![Linting](https://github.com/zackees/disklru/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/disklru/actions/workflows/lint.yml)\n\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)\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)\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)\n\n\n# Usage\n\n```python\nfrom disklru import DiskLRUCache\n\nLRU_CACHE_FILE = \"cache.db\"\nMAX_ENTRIES = 4\ncache = DiskLRUCache(LRU_CACHE_FILE, MAX_ENTRIES)\ncache.put(\"key\", \"value\")\nassert cache.get(\"key1\") == \"val\"\ncache.clear()\n```\n\n# API\n\n```python\nclass DiskLRUCache:\n \"\"\"Disk-based LRU cache using SQLite.\"\"\"\n\n def get(self, key: str) -> str | None:\n \"\"\"Returns the value associated with the given key, or None if the key is not in the cache.\"\"\"\n\n def get_json(self, key: str) -> Any:\n \"\"\"Returns the value associated with the given key, or None if the key is not in the cache.\"\"\"\n\n def put(self, key: str, value: str) -> None:\n \"\"\"Sets the value associated with the given key.\"\"\"\n\n def put_json(self, key: str, val: Any) -> None:\n \"\"\"Sets the value associated with the given key.\"\"\"\n\n def delete(self, key) -> None:\n \"\"\"Deletes the given key from the cache.\"\"\"\n\n def purge(self, timestamp) -> None:\n \"\"\"Purges all elements less than the timestamp.\"\"\"\n\n def clear(self) -> None:\n \"\"\"Clears the cache.\"\"\"\n\n def __del__(self) -> None:\n \"\"\"Destructor.\"\"\"\n self.close()\n\n def close(self) -> None:\n \"\"\"Closes the connection to the database.\"\"\"\n```\n\n# Development\n\n### Windows\n\nThis environment requires you to use `git-bash`.\n\n### Linting\n\nRun `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License",
"summary": "Creates a python disk LRU / cache - great for apps that want to save data",
"version": "1.0.7",
"project_urls": {
"Homepage": "https://github.com/zackees/disklru"
},
"split_keywords": [
"disk",
"lru",
"cache",
"least",
"recently",
"used"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ad60c89766ae48bc2ff15e2715fd9c532fa506358b3b5605115879f838ead077",
"md5": "73f6e5d8c34285ec898ad010e05c1e7e",
"sha256": "dc37b3576a903cf24605bcf231925d4eeb9753c275156db1b9abe977c9931dab"
},
"downloads": -1,
"filename": "disklru-1.0.7-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "73f6e5d8c34285ec898ad010e05c1e7e",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 4155,
"upload_time": "2023-06-23T18:13:42",
"upload_time_iso_8601": "2023-06-23T18:13:42.035521Z",
"url": "https://files.pythonhosted.org/packages/ad/60/c89766ae48bc2ff15e2715fd9c532fa506358b3b5605115879f838ead077/disklru-1.0.7-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "067d2d05244be999ac4d140020ac5f5b210d50c2f288effacff40dee1ca59b58",
"md5": "01c8276e24f4dbd8d9be6ef3702d1ffb",
"sha256": "0d17d747937d70707bd5739d97f2aaf39af0b794e70b1e8fb340a325fee5af0d"
},
"downloads": -1,
"filename": "disklru-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "01c8276e24f4dbd8d9be6ef3702d1ffb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10172,
"upload_time": "2023-06-23T18:13:43",
"upload_time_iso_8601": "2023-06-23T18:13:43.595463Z",
"url": "https://files.pythonhosted.org/packages/06/7d/2d05244be999ac4d140020ac5f5b210d50c2f288effacff40dee1ca59b58/disklru-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-23 18:13:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zackees",
"github_project": "disklru",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "disklru"
}