Skip to main content

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

Project description

ruff 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.json")
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.json", 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 of Queue.

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zcache-3.0.5-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zcache-3.0.5.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.20

File hashes

Hashes for zcache-3.0.5.tar.gz
Algorithm Hash digest
SHA256 d0222535c98d35ed1f41c439cdd5835b5bbab03ec520744f9bbac00598f3c19a
MD5 9daca2dc9448cd1bdb2d8f02b406f192
BLAKE2b-256 bf84b2461f511e8308d5cdcfc896da19c8a96b3972b1333dcaaf8518070fe45a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zcache-3.0.5-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.20

File hashes

Hashes for zcache-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 696666fc2f2f683fe073a63202fc3f59bb5bf363a0a7c7e82a64de90fd38a7af
MD5 2cb9dff6231e1efff911a6b28a96dd3a
BLAKE2b-256 0bc5e7f328ffa4d0416b1633026eff27f97aed2b31c3dc481ed20d4a2b07615d

See more details on using hashes here.

Supported by

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