https://github.com/calpaterson/pyappcache
A library for application-level caching
https://github.com/calpaterson/pyappcache
cache library
Last synced: 12 months ago
JSON representation
A library for application-level caching
- Host: GitHub
- URL: https://github.com/calpaterson/pyappcache
- Owner: calpaterson
- License: gpl-3.0
- Created: 2020-06-15T16:34:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T10:45:28.000Z (about 2 years ago)
- Last Synced: 2025-03-22T18:03:53.410Z (over 1 year ago)
- Topics: cache, library
- Language: Python
- Homepage: https://pyappcache.readthedocs.io/en/latest/
- Size: 159 KB
- Stars: 21
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
pyappcache
==========
Pyappcache is a library to make it easier to use application-level
caching in Python.
- Allows putting arbitrary Python objects into the cache
- Uses PEP484 type hints to help you typecheck cache return values
- Supports Memcache, Redis and SQLite
- Supports working as a "read-through" and "write-through" cache
- Native support for key `"namespacing" `__
- Provides a few handy extras
- A plugin for the
`cachecontrol `__ library
so you can also use it as an HTTP cache with
`requests `__
A simple example
----------------
.. code:: python
from datetime import date
from pyappcache.redis import RedisCache
from pyappcache.keys import Key, SimpleStringKey
cache = RedisCache()
# Annotate the type here to let mypy know this key is used for dates
key: Key[date] = SimpleStringKey("mifid start date")
cache.set(key, date(2018, 1, 3), ttl_seconds=3600)
... # later...
# This variable's type will be inferred as datetime.date
special_date = cache.get(key)
How it compares to alternatives
-------------------------------
Using the redis/memcache/sqlite client directly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Explicit key objects allow for type inference and encapsulation of keying
- Keys are prefix to help prevent collisions
- Optional, pluggable, compression
- Hopefully the overhead is small (not yet tested!)
- Portable between redis/memcache/sqlite, etc
dogpile.cache
~~~~~~~~~~~~~
- Explicit key objects allow for type inference and encapsulation of keying
- dogpile.cache provides locking, pyappcache does not
- Reduced temptation to use the problematic decorator pattern
- This often causes import order problems as you need to have your cache at import time
- Pyappache doesn't provide DBM/file backends, SQLite instead