[![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![status workflow test](https://github.com/guangrei/zcache/actions/workflows/python-app.yml/badge.svg)](https://github.com/guangrei/zcache/actions)
[![status workflow build](https://github.com/guangrei/zcache/actions/workflows/release_to_pypi.yml/badge.svg)](https://github.com/guangrei/zcache/actions)
[![Downloads](https://static.pepy.tech/badge/zcache)](https://pepy.tech/project/zcache)
[![Downloads](https://static.pepy.tech/badge/zcache/month)](https://pepy.tech/project/zcache)
[![Downloads](https://static.pepy.tech/badge/zcache/week)](https://pepy.tech/project/zcache)
zcache is pure typed Python implementation of key value Cache/Database with abstract storage, plugins and asynchronous support.
## Installation
```
pip install zcache
```
# example
basic example:
```python
from zcache import Cache
import time
c = Cache(path="/tmp/tes1.json")
print("set foo=bar: ", c.set("foo", "bar"))
print("c size:", c.size())
print("c has foo: ", c.has("foo"))
print("c get foo: ", c.get("foo"))
print("c delete foo: ", c.delete("foo"))
print("c has foo: ", c.has("foo"))
print("c has spam:", c.has("spam"))
print("c set spam=eggs, ttl=3: ", c.set("spam", "eggs", ttl=3)) # cache with ttl
print("c has spam:", c.has("spam"))
print("sleep 3")
time.sleep(3)
print("c has spam:", c.has("spam"))
print("c size:", c.size())
```
example with limited stack:
```python
from zcache import Cache
d = Cache(path="/tmp/test2.json", limit=2)
d.reset() # reset cache stack to 0
print(d.set("one", 1)) # True
print(d.set("two", 2)) # True
print(d.set("three", 3)) # False out of stack limit
d.delete("one") # delete one item from stack
print(d.set("three", 3)) # True
```
# Asynchronous
example asynchronous usage
```python
import asyncio
from zcache import AsyncCache
async def main():
c = AsyncCache()
await c.init()
await c.set("test", "OK")
print(await c.get("test"))
if __name__ == '__main__':
asyncio.run(main())
```
# Storage and plugins
you can change storage and use plugins, for example:
```python
from zcache import Cache
from zcache.Plugins.BytesCachePlugins import BytesCachePlugins
from zcache.Storage.BaseFileStorage import BaseFileStorage
storage = BaseFileStorage("/tmp/zcache.json")
plugins = BytesCachePlugins()
c = Cache(storage=storage, plugins=plugins)
```
see list current available [storage](https://github.com/guangrei/zcache/tree/main/zcache/Storage) and [plugins](https://github.com/guangrei/zcache/tree/main/zcache/Plugins), you can also create your own storage and plugins.
# Extras
[Extras](https://github.com/guangrei/zcache/tree/main/zcache/Extras) is several module based on zcache.
1. [SmartRequest](https://github.com/guangrei/zcache/blob/main/Tests/test_smartrequest.py)
`SmartRequest` is Simple HTTP Client with smart caching system based on `zcache`.
2.[AsyncSmartRequest](https://github.com/guangrei/zcache/blob/main/Tests/test_async_smartrequest.py)
`AsyncSmartRequest` is asynchronous version of `SmartRequests`.
3. [Queue](https://github.com/guangrei/zcache/blob/main/Tests/test_queue.py)
`Queue` is Fifo Queue based on `zcache`.
4. [AsyncQueue](https://github.com/guangrei/zcache/blob/main/Tests/test_async_queue.py)
`AsyncQueue` is asynchronous version of `Queue`.
## License
MIT
Raw data
{
"_id": null,
"home_page": "https://github.com/guangrei/zcache",
"name": "zcache",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "cache key value file json",
"author": "guangrei",
"author_email": "myawn@pm.me",
"download_url": "https://files.pythonhosted.org/packages/bf/84/b2461f511e8308d5cdcfc896da19c8a96b3972b1333dcaaf8518070fe45a/zcache-3.0.5.tar.gz",
"platform": null,
"description": "[![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) \n[![status workflow test](https://github.com/guangrei/zcache/actions/workflows/python-app.yml/badge.svg)](https://github.com/guangrei/zcache/actions) \n[![status workflow build](https://github.com/guangrei/zcache/actions/workflows/release_to_pypi.yml/badge.svg)](https://github.com/guangrei/zcache/actions)\n\n[![Downloads](https://static.pepy.tech/badge/zcache)](https://pepy.tech/project/zcache)\n[![Downloads](https://static.pepy.tech/badge/zcache/month)](https://pepy.tech/project/zcache)\n[![Downloads](https://static.pepy.tech/badge/zcache/week)](https://pepy.tech/project/zcache)\n\nzcache is pure typed Python implementation of key value Cache/Database with abstract storage, plugins and asynchronous support.\n\n## Installation\n```\npip install zcache\n```\n# example\n\nbasic example:\n```python\nfrom zcache import Cache\nimport time\n\nc = Cache(path=\"/tmp/tes1.json\")\nprint(\"set foo=bar: \", c.set(\"foo\", \"bar\"))\nprint(\"c size:\", c.size())\nprint(\"c has foo: \", c.has(\"foo\"))\nprint(\"c get foo: \", c.get(\"foo\"))\nprint(\"c delete foo: \", c.delete(\"foo\"))\nprint(\"c has foo: \", c.has(\"foo\"))\nprint(\"c has spam:\", c.has(\"spam\"))\nprint(\"c set spam=eggs, ttl=3: \", c.set(\"spam\", \"eggs\", ttl=3)) # cache with ttl\nprint(\"c has spam:\", c.has(\"spam\"))\nprint(\"sleep 3\")\ntime.sleep(3)\nprint(\"c has spam:\", c.has(\"spam\"))\nprint(\"c size:\", c.size())\n```\nexample with limited stack:\n```python\nfrom zcache import Cache\n\nd = Cache(path=\"/tmp/test2.json\", limit=2)\nd.reset() # reset cache stack to 0\nprint(d.set(\"one\", 1)) # True\nprint(d.set(\"two\", 2)) # True\nprint(d.set(\"three\", 3)) # False out of stack limit\nd.delete(\"one\") # delete one item from stack\nprint(d.set(\"three\", 3)) # True\n```\n\n# Asynchronous\n\nexample asynchronous usage\n\n```python\nimport asyncio\nfrom zcache import AsyncCache\n\nasync def main():\n c = AsyncCache()\n await c.init()\n await c.set(\"test\", \"OK\")\n print(await c.get(\"test\"))\n\nif __name__ == '__main__':\n asyncio.run(main())\n```\n\n# Storage and plugins\n\nyou can change storage and use plugins, for example:\n\n```python\nfrom zcache import Cache\nfrom zcache.Plugins.BytesCachePlugins import BytesCachePlugins\nfrom zcache.Storage.BaseFileStorage import BaseFileStorage\n\n\nstorage = BaseFileStorage(\"/tmp/zcache.json\")\nplugins = BytesCachePlugins()\nc = Cache(storage=storage, plugins=plugins)\n```\nsee list current available [storage](https://github.com/guangrei/zcache/tree/main/zcache/Storage) and [plugins](https://github.com/guangrei/zcache/tree/main/zcache/Plugins), you can also create your own storage and plugins.\n\n# Extras\n\n[Extras](https://github.com/guangrei/zcache/tree/main/zcache/Extras) is several module based on zcache.\n\n1. [SmartRequest](https://github.com/guangrei/zcache/blob/main/Tests/test_smartrequest.py)\n\n`SmartRequest` is Simple HTTP Client with smart caching system based on `zcache`.\n\n2.[AsyncSmartRequest](https://github.com/guangrei/zcache/blob/main/Tests/test_async_smartrequest.py)\n\n`AsyncSmartRequest` is asynchronous version of `SmartRequests`.\n\n3. [Queue](https://github.com/guangrei/zcache/blob/main/Tests/test_queue.py)\n\n`Queue` is Fifo Queue based on `zcache`.\n\n4. [AsyncQueue](https://github.com/guangrei/zcache/blob/main/Tests/test_async_queue.py)\n\n`AsyncQueue` is asynchronous version of `Queue`.\n\n\n## License\n\nMIT\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pure typed Python Key Value Database/Cache with abstract storage, plugins and asynchronous support",
"version": "3.0.5",
"project_urls": {
"Homepage": "https://github.com/guangrei/zcache"
},
"split_keywords": [
"cache",
"key",
"value",
"file",
"json"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0bc5e7f328ffa4d0416b1633026eff27f97aed2b31c3dc481ed20d4a2b07615d",
"md5": "2cb9dff6231e1efff911a6b28a96dd3a",
"sha256": "696666fc2f2f683fe073a63202fc3f59bb5bf363a0a7c7e82a64de90fd38a7af"
},
"downloads": -1,
"filename": "zcache-3.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2cb9dff6231e1efff911a6b28a96dd3a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 28246,
"upload_time": "2024-12-01T15:57:53",
"upload_time_iso_8601": "2024-12-01T15:57:53.038727Z",
"url": "https://files.pythonhosted.org/packages/0b/c5/e7f328ffa4d0416b1633026eff27f97aed2b31c3dc481ed20d4a2b07615d/zcache-3.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bf84b2461f511e8308d5cdcfc896da19c8a96b3972b1333dcaaf8518070fe45a",
"md5": "9daca2dc9448cd1bdb2d8f02b406f192",
"sha256": "d0222535c98d35ed1f41c439cdd5835b5bbab03ec520744f9bbac00598f3c19a"
},
"downloads": -1,
"filename": "zcache-3.0.5.tar.gz",
"has_sig": false,
"md5_digest": "9daca2dc9448cd1bdb2d8f02b406f192",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11998,
"upload_time": "2024-12-01T15:57:54",
"upload_time_iso_8601": "2024-12-01T15:57:54.676457Z",
"url": "https://files.pythonhosted.org/packages/bf/84/b2461f511e8308d5cdcfc896da19c8a96b3972b1333dcaaf8518070fe45a/zcache-3.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-01 15:57:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "guangrei",
"github_project": "zcache",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "zcache"
}