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

Uploaded Source

Built Distribution

zcache-1.0.11-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zcache-1.0.11.tar.gz
  • Upload date:
  • Size: 16.4 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.11.tar.gz
Algorithm Hash digest
SHA256 bcfe0c01dbb1174de14baaba726f4f567605602efb492db9fb9ca9ab8dfae981
MD5 d3b05340d03835ea204e699437dcdfe2
BLAKE2b-256 a0d52cb794153f7140e778be32fcbe292f40a92594369bb931cdf230ec914ea1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zcache-1.0.11-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 da07b87531a26375bc1af7365d3ceee167d6997de6965cfdf1eae04fda7e033d
MD5 1b49702da1583d5bddce79721d211bfe
BLAKE2b-256 18f66f760ad4b8a9eaab5e5743c95b1c36acf1490b7ff00f65051cf7c0fcab6d

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