Metadata-Version: 2.1
Name: pyappcache
Version: 0.9.1
Home-page: https://github.com/calpaterson/pyappcache
Author: Cal Paterson
Author-email: cal@calpaterson.com
Project-URL: Documentation, https://pyappcache.readthedocs.io/en/latest/
Project-URL: Code, https://github.com/calpaterson/pyappcache
Project-URL: Issue tracker, https://github.com/calpaterson/pyappcache/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: COPYING
Requires-Dist: typing-extensions
Requires-Dist: python-dateutil
Provides-Extra: dev
Requires-Dist: bpython (~=0.18) ; extra == 'dev'
Provides-Extra: memcache
Requires-Dist: pylibmc ; extra == 'memcache'
Provides-Extra: redis
Requires-Dist: redis (>=3) ; extra == 'redis'
Provides-Extra: tests
Requires-Dist: black (~=22.10.0) ; extra == 'tests'
Requires-Dist: cachecontrol (<=0.12.6) ; extra == 'tests'
Requires-Dist: flask (~=2.2.2) ; extra == 'tests'
Requires-Dist: mypy (==0.991) ; extra == 'tests'
Requires-Dist: pyflakes ; extra == 'tests'
Requires-Dist: pytest-cov ; extra == 'tests'
Requires-Dist: pytest (~=7.2.0) ; extra == 'tests'
Requires-Dist: requests ; extra == 'tests'
Requires-Dist: sphinx-autodoc-typehints (~=1.19.5) ; extra == 'tests'
Requires-Dist: sphinx (==5.3.0) ; extra == 'tests'
Requires-Dist: time-machine (~=2.8.2) ; extra == 'tests'
Requires-Dist: types-python-dateutil ; extra == 'tests'
Requires-Dist: types-redis ; extra == 'tests'
Requires-Dist: types-requests ; extra == 'tests'
Requires-Dist: wheel ; extra == 'tests'
Requires-Dist: pylibmc ; extra == 'tests'
Requires-Dist: redis (>=3) ; extra == 'tests'

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" <https://github.com/memcached/memcached/wiki/ProgrammingTricks#namespacing>`__
-  Provides a few handy extras

   -  A plugin for the
      `cachecontrol <https://pypi.org/project/CacheControl/>`__ library
      so you can also use it as an HTTP cache with
      `requests <https://pypi.org/project/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
