Skip to main content

Key Value Database/Cache with abstract storage and plugins

Project description

status workflow test status workflow build

Downloads Downloads Downloads

zcache is pure python implementation of key value Cache/Database with abstract storage and plugins 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

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.

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-1.0.9.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

zcache-1.0.9-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zcache-1.0.9.tar.gz
Algorithm Hash digest
SHA256 f6492c7142717afc6ab4da900580ab554880b192b48ec4a60ce4f3f1a686d474
MD5 b1fc0cd78d4c5c12a161481feaf86a27
BLAKE2b-256 4e119e2859923aeea76c0ebfc4eae16e489c9dffda0f312fc4b8452f9896d53c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zcache-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 15.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-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8e0444ed3d6ef08a2a0e99ea9c86d48c8abb58e3daa6782f2148b229fe8e80e5
MD5 275306c800cff81c50a22f7652e027a1
BLAKE2b-256 1a8a47faf9f98f0f396a3d48c26232bf145646dae607efc5cbbd33e7206cdf23

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