Skip to main content

Pure typed Python Key Value Database/Cache with abstract storage, plugins and asynchronous support

Project description

status workflow test status workflow build

Downloads Downloads Downloads

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.

  1. SmartRequest

SmartRequest is Simple HTTP Client with smart caching system based on zcache.

2.AsyncSmartRequest

AsyncSmartRequest is asynchronous version of SmartRequests.

  1. Queue

Queue is Fifo Queue based on zcache.

  1. AsyncQueue

AsyncQueue is asynchronous version ofzcache.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zcache-3.0.3.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

zcache-3.0.3-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file zcache-3.0.3.tar.gz.

File metadata

  • Download URL: zcache-3.0.3.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for zcache-3.0.3.tar.gz
Algorithm Hash digest
SHA256 a68db770221e90c2cc76c3cad07d1adc78878ea7a0daa40a1e77ffa21537746d
MD5 e98074876e341c6cc4b3442d62c6649d
BLAKE2b-256 4c29a1a9fb543bbc82d2099784603727104c72ae013b199f8cd9ffb3f4c56937

See more details on using hashes here.

File details

Details for the file zcache-3.0.3-py3-none-any.whl.

File metadata

  • Download URL: zcache-3.0.3-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for zcache-3.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5a8e449456d633e4efccc0cd560f1f6bec9381bd60f9cf1147f0e872d841da57
MD5 4d1c5503e05e2f96b75739d710a18fc3
BLAKE2b-256 6a715f3dcd4217106c8f11f3530594713af3b9525304bcda3c48a92ba9c6bb83

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page