Skip to main content

Python caching library with tag-based invalidation and dogpile effect prevention

Project description

Pipeline status Test code coverage PyPI RTFD

HermesCache

Hermes is a Python caching library. It was designed to fulfil the following requirements:

  • Tag-based O(1) cache invalidation

  • Dogpile effect (cache stampede) mitigation

  • Support for multi-threaded, multi-process and multi-machine operation

  • Cache compression

  • Modular design (pluggable backends, compressors, serialisers, etc.)

  • Simple yet flexible decorator API

Implemented backends: redis, memcached, dict.

Installation

pip install HermesCache

For Redis and Memcached it has the following extra dependencies.

HermesCache[redis]

Pure Python Redis client

HermesCache[redis-ext]

Pure Python Redis client & C extension parser

HermesCache[memcached]

Pure Python Memcached client

HermesCache[memcached-ext]

C extension Memcached client

Quickstart

The following demonstrates the most of the package’s API.

import hermes.backend.redis


cache = hermes.Hermes(
  hermes.backend.redis.Backend,
  ttl = 600,
  host = 'localhost',
  db = 1,
)

@cache
def foo(a, b):
  return a * b

class Example:

  @cache(tags = ('math', 'power'), ttl = 1200)
  def bar(self, a, b):
    return a ** b

  @cache(tags = ('math', 'avg'), key = lambda fn, a, b: f'avg:{a}:{b}')
  def baz(self, a, b):
    return (a + b) / 2

print(foo(2, 333))

example = Example()
print(example.bar(2, 10))
print(example.baz(2, 10))

foo.invalidate(2, 333)
example.bar.invalidate(2, 10)
example.baz.invalidate(2, 10)

cache.clean(['math']) # invalidate entries tagged 'math'
cache.clean()         # flush cache

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

HermesCache-0.9.0.tar.gz (21.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: HermesCache-0.9.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for HermesCache-0.9.0.tar.gz
Algorithm Hash digest
SHA256 83df527df7857e2b293785c0f2acf8e70e3cadbcb140404306d16f047628a023
MD5 64816ca5a631d5c7e8f760ea08f4303d
BLAKE2b-256 e0975558912ef0adae74d0c428c3cdd60bbce76806299f595dc488ddbfb956ea

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