.. image:: https://img.shields.io/pypi/l/HermesCache.svg
:target: https://spdx.org/licenses/LGPL-2.1+.html
:alt: PyPI - License
.. image:: https://heptapod.host/saajns/hermes/badges/branch/default/pipeline.svg
:target: https://heptapod.host/saajns/hermes/-/commits/branch/default
:alt: Pipeline status
.. image:: https://heptapod.host/saajns/hermes/badges/branch/default/coverage.svg
:target: https://hermescache.readthedocs.io/en/report/htmlcov/?badge=coverage
:alt: Test code coverage
.. image:: https://img.shields.io/badge/benchmarked%20by-asv-blue.svg?style=flat
:target: https://hermescache.readthedocs.io/en/report/htmlasv/?badge=asv
:alt: Benchmark
.. image:: https://badge.fury.io/py/HermesCache.svg
:target: https://pypi.python.org/pypi/HermesCache
:alt: PyPI
.. image:: https://readthedocs.org/projects/hermescache/badge/?version=latest
:target: https://hermescache.readthedocs.io/en/latest/?badge=latest
:alt: 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, multi-machine & asynchronous operation
* Cache compression
* Modular design (pluggable backends, compressors, serialisers, etc.)
* Simple yet flexible decorator API
Implemented backends: ``redis``, ``memcached``, ``inprocess``.
Installation
============
.. sourcecode::
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
============================== =============================================
Quickstart
==========
The following demonstrates the most of the package's API.
.. sourcecode:: python
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
.. note::
The API encourages import-time instantiation of ``Hermes`` facade to allow
decoration of existing classes and functions, to make caching transparent
to them. The instantiation has no side-effects. Underlying backend
connections are lazy.
Moreover, if backend configuration is only available at runtime,
``Hermes.backend`` instance can be replaced at runtime.
Raw data
{
"_id": null,
"home_page": "https://heptapod.host/saajns/hermes",
"name": "HermesCache",
"maintainer": "",
"docs_url": null,
"requires_python": ">= 3",
"maintainer_email": "",
"keywords": "python cache tagging redis memcached",
"author": "saaj",
"author_email": "mail@saaj.me",
"download_url": "https://files.pythonhosted.org/packages/46/89/2bb807d45052e3ec63af6d38c8a01ee5760711c9184165688fb3d850c877/HermesCache-1.0.0.tar.gz",
"platform": "Any",
"description": ".. image:: https://img.shields.io/pypi/l/HermesCache.svg\n :target: https://spdx.org/licenses/LGPL-2.1+.html\n :alt: PyPI - License\n.. image:: https://heptapod.host/saajns/hermes/badges/branch/default/pipeline.svg\n :target: https://heptapod.host/saajns/hermes/-/commits/branch/default\n :alt: Pipeline status\n.. image:: https://heptapod.host/saajns/hermes/badges/branch/default/coverage.svg\n :target: https://hermescache.readthedocs.io/en/report/htmlcov/?badge=coverage\n :alt: Test code coverage\n.. image:: https://img.shields.io/badge/benchmarked%20by-asv-blue.svg?style=flat\n :target: https://hermescache.readthedocs.io/en/report/htmlasv/?badge=asv\n :alt: Benchmark\n.. image:: https://badge.fury.io/py/HermesCache.svg\n :target: https://pypi.python.org/pypi/HermesCache\n :alt: PyPI\n.. image:: https://readthedocs.org/projects/hermescache/badge/?version=latest\n :target: https://hermescache.readthedocs.io/en/latest/?badge=latest\n :alt: RTFD\n\n***********\nHermesCache\n***********\nHermes is a Python caching library. It was designed to fulfil the following\nrequirements:\n\n* Tag-based O(1) cache invalidation\n* Dogpile effect (cache stampede) mitigation\n* Support for multi-threaded, multi-process, multi-machine & asynchronous operation\n* Cache compression\n* Modular design (pluggable backends, compressors, serialisers, etc.)\n* Simple yet flexible decorator API\n\nImplemented backends: ``redis``, ``memcached``, ``inprocess``.\n\nInstallation\n============\n.. sourcecode::\n\n pip install HermesCache\n\nFor Redis and Memcached it has the following extra dependencies.\n\n============================== =============================================\n``HermesCache[redis]`` Pure Python Redis client\n------------------------------ ---------------------------------------------\n``HermesCache[redis-ext]`` Pure Python Redis client & C extension parser\n------------------------------ ---------------------------------------------\n``HermesCache[memcached]`` Pure Python Memcached client\n============================== =============================================\n\nQuickstart\n==========\nThe following demonstrates the most of the package's API.\n\n.. sourcecode:: python\n\n import hermes.backend.redis\n\n\n cache = hermes.Hermes(\n hermes.backend.redis.Backend,\n ttl = 600,\n host = 'localhost',\n db = 1,\n )\n\n @cache\n def foo(a, b):\n return a * b\n\n class Example:\n\n @cache(tags = ('math', 'power'), ttl = 1200)\n def bar(self, a, b):\n return a ** b\n\n @cache(tags = ('math', 'avg'), key = lambda fn, a, b: f'avg:{a}:{b}')\n def baz(self, a, b):\n return (a + b) / 2\n\n print(foo(2, 333))\n\n example = Example()\n print(example.bar(2, 10))\n print(example.baz(2, 10))\n\n foo.invalidate(2, 333)\n example.bar.invalidate(2, 10)\n example.baz.invalidate(2, 10)\n\n cache.clean(['math']) # invalidate entries tagged 'math'\n cache.clean() # flush cache\n\n.. note::\n\n The API encourages import-time instantiation of ``Hermes`` facade to allow\n decoration of existing classes and functions, to make caching transparent\n to them. The instantiation has no side-effects. Underlying backend\n connections are lazy.\n\n Moreover, if backend configuration is only available at runtime,\n ``Hermes.backend`` instance can be replaced at runtime.\n",
"bugtrack_url": null,
"license": "LGPL-2.1+",
"summary": "Python caching library with tag-based invalidation and dogpile effect prevention",
"version": "1.0.0",
"project_urls": {
"Documentation": "https://hermescache.readthedocs.io/",
"Homepage": "https://heptapod.host/saajns/hermes",
"Release Notes": "https://hermescache.readthedocs.io/en/latest/history.html",
"Source Code": "https://heptapod.host/saajns/hermes"
},
"split_keywords": [
"python",
"cache",
"tagging",
"redis",
"memcached"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "46892bb807d45052e3ec63af6d38c8a01ee5760711c9184165688fb3d850c877",
"md5": "8ed9f23c36faac667fc92a95e03b0c29",
"sha256": "fa79dde04d1295176805c0fd2c146ce5c374a10700328b04c3d6b402b3e576ab"
},
"downloads": -1,
"filename": "HermesCache-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "8ed9f23c36faac667fc92a95e03b0c29",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">= 3",
"size": 24489,
"upload_time": "2024-03-10T20:29:06",
"upload_time_iso_8601": "2024-03-10T20:29:06.328098Z",
"url": "https://files.pythonhosted.org/packages/46/89/2bb807d45052e3ec63af6d38c8a01ee5760711c9184165688fb3d850c877/HermesCache-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-10 20:29:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "hermescache"
}