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

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

0.9.0

Initial version extracted from another project.

TODO

  • improve documentation
  • add __version__

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

Uploaded Source

Built Distribution

CacheToolsUtils-0.9.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: CacheToolsUtils-0.9.0.tar.gz
  • Upload date:
  • Size: 4.2 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-0.9.0.tar.gz
Algorithm Hash digest
SHA256 635615bee0ab5870e09eff24575615543617c4ae0f1103e5660ce88d6af1baaa
MD5 1fad65d6701b9a034889b3a2df3e2080
BLAKE2b-256 295d82828de0d47d1cfe4ba503fa0f2b137dc38696a384c90e76f95e431535c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: CacheToolsUtils-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 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-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d31656ec940db624a557e02b9cbf8dcc49d19a192d95b755bbb631ed5470df57
MD5 5efdadd5d1e739dca0fadb318850c582
BLAKE2b-256 061256e13fd9881f973c3394a237d3a551f8a1ea978661314b33f9c39fc4e25c

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