Skip to main content

Cachetools Utilities

Project description

cachetools-utils

Classes to add key prefix and stats to cachetools classes and use redis and memcached as storage backends.

Usage

Install with pip:

pip install CacheToolsUtils

See below.

Documentation

This module provide the following cache wrappers suitable to use with cachetools:

PrefixedCache

Add a key prefix.

import CacheToolsUtils as ctu

base = cachetools.TTLCache(ttl=600)
foo_cache = ctu.PrefixedCache(base, "foo.")
bla_cache = ctu.PrefixedCache(base, "bla.")

@cachetools.cached(cache=foo_cache)
def foo():
    return 

@cachetools.cached(cache=bla_cache)
def bla():
    return 

StatsCache

Keep stats, cache hit rate shown with hits().

MemCached

Basic wrapper with JSON key encoding.

import pymemcache as pmc

mcbase = pmc.Client(server="localhost", serde=ctu.JsonSerde())
cache = ctu.MemCached(mcbase)

@cachetools.cached(cache=cache)
def poc():

PrefixedMemCached

Wrapper with a prefix.

pcache = ctu.PrefixedMemCached(mcbase, prefix="pic.")

StatsMemCached

Wrapper with stats actually taken from the MemCached server.

RedisCache

TTL'ed Redis wrapper, default ttl is 10 minutes.

import redis

rd_base = redis.Redis(, ttl=60)
cache = ctu.RedisCache(rd_base)

PrefixedRedisCache

Wrapper with a prefix and a ttl.

StatsRedisCache

Wrapper with stats (call hits()) and a ttl.

License

This code is public domain.

Versions

1.0.0 on 2022-01-29

Add set, get and delete forwarding to RedisCache, so that redis classes can be stacked.

0.9.0 on 2022-01-29

Initial version extracted from another project.

TODO

  • improve documentation
  • add a close?

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

CacheToolsUtils-1.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

CacheToolsUtils-1.0.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file CacheToolsUtils-1.0.0.tar.gz.

File metadata

  • Download URL: CacheToolsUtils-1.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for CacheToolsUtils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8cd2bd0fbad9bba5b85e36d55999fa4a9175db6c6a3ee01fbfc0de0e5145ba5c
MD5 4c222750e6d578b0f9083fb0fbd30985
BLAKE2b-256 76d024f0ffa71702d166036447d93a0d7988bfdb3c063f841052b00fce58d628

See more details on using hashes here.

File details

Details for the file CacheToolsUtils-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: CacheToolsUtils-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for CacheToolsUtils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68feaf667435ed6c7542db4ba6dcbed53c9cc8f0d55c490b73186a2ca8ff7500
MD5 f6d1002723bc688eeac6fe94c5a5a01d
BLAKE2b-256 9d1f21b4cc96ba8536b912b05f408b2f41bbf9fa0b958a563ae81eb05d815e82

See more details on using hashes here.

Supported by

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