zcache


Namezcache JSON
Version 3.0.4 PyPI version JSON
download
home_pagehttps://github.com/guangrei/zcache
SummaryPure typed Python Key Value Database/Cache with abstract storage, plugins and asynchronous support
upload_time2024-11-09 15:21:38
maintainerNone
docs_urlNone
authorguangrei
requires_pythonNone
licenseMIT
keywords cache key value file json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![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.cache")
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.cache", 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/7a/08/cd8d994718091436fda0691e8cffa01c14ecd3487c99c7cfa83fc4c682e5/zcache-3.0.4.tar.gz",
    "platform": null,
    "description": "[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\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.cache\")\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.cache\", 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.4",
    "project_urls": {
        "Homepage": "https://github.com/guangrei/zcache"
    },
    "split_keywords": [
        "cache",
        "key",
        "value",
        "file",
        "json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6b24b436f5f53a2dfa784dcbf7d69e40172e5df6030c84926a4b0d8363c891f",
                "md5": "7706dd17d0673a6ef4be9576e1faf14d",
                "sha256": "740ddbc4af6921992f55a1f85aa2421e1e913069606d82574d0d7ff193f6ad39"
            },
            "downloads": -1,
            "filename": "zcache-3.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7706dd17d0673a6ef4be9576e1faf14d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 28096,
            "upload_time": "2024-11-09T15:21:36",
            "upload_time_iso_8601": "2024-11-09T15:21:36.382213Z",
            "url": "https://files.pythonhosted.org/packages/c6/b2/4b436f5f53a2dfa784dcbf7d69e40172e5df6030c84926a4b0d8363c891f/zcache-3.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a08cd8d994718091436fda0691e8cffa01c14ecd3487c99c7cfa83fc4c682e5",
                "md5": "97ea4288765b368c0f72da24ea4c2098",
                "sha256": "06ee6ae9d68a6c65efbc2967b1410cf5404024d54f5290c92c857566d8878e1f"
            },
            "downloads": -1,
            "filename": "zcache-3.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "97ea4288765b368c0f72da24ea4c2098",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11925,
            "upload_time": "2024-11-09T15:21:38",
            "upload_time_iso_8601": "2024-11-09T15:21:38.010488Z",
            "url": "https://files.pythonhosted.org/packages/7a/08/cd8d994718091436fda0691e8cffa01c14ecd3487c99c7cfa83fc4c682e5/zcache-3.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-09 15:21:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "guangrei",
    "github_project": "zcache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "zcache"
}
        
Elapsed time: 2.28125s