Pure typed Python Key Value Database/Cache with abstract storage, plugins and asynchronous support
Project description
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:
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:
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
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:
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 and plugins, you can also create your own storage and plugins.
Extras
Extras is several module based on zcache.
SmartRequest
is Simple HTTP Client with smart caching system based on zcache
.
AsyncSmartRequest
is asynchronous version of SmartRequests
.
Queue
is Fifo Queue based on zcache
.
AsyncQueue
is asynchronous version of Queue
.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file zcache-3.0.4.tar.gz
.
File metadata
- Download URL: zcache-3.0.4.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06ee6ae9d68a6c65efbc2967b1410cf5404024d54f5290c92c857566d8878e1f |
|
MD5 | 97ea4288765b368c0f72da24ea4c2098 |
|
BLAKE2b-256 | 7a08cd8d994718091436fda0691e8cffa01c14ecd3487c99c7cfa83fc4c682e5 |
File details
Details for the file zcache-3.0.4-py3-none-any.whl
.
File metadata
- Download URL: zcache-3.0.4-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 740ddbc4af6921992f55a1f85aa2421e1e913069606d82574d0d7ff193f6ad39 |
|
MD5 | 7706dd17d0673a6ef4be9576e1faf14d |
|
BLAKE2b-256 | c6b24b436f5f53a2dfa784dcbf7d69e40172e5df6030c84926a4b0d8363c891f |