Skip to main content

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

Project description

PyPI - License Pipeline status Test code coverage PyPI RTFD


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, inprocess.


pip install HermesCache

For Redis and Memcached it has the following extra dependencies.


Pure Python Redis client


Pure Python Redis client & C extension parser


Pure Python Memcached client


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

import hermes.backend.redis

cache = hermes.Hermes(
  ttl = 600,
  host = 'localhost',
  db = 1,

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(, 10))
print(example.baz(2, 10))

foo.invalidate(2, 333), 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.10.0.tar.gz (24.3 kB view hashes)

Uploaded Source

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