safecache

Verizon


Keywords
disk-cache, memory-cache, policy-based-routing, thread-safe, type-safe
License
MIT
Install
pip install safecache==0.0.1

Documentation

Build Status

A thread-safe and mutation-safe LRU cache for Python.

Features

  • All cached entries are mutation-safe.
  • All cached entries are thread-safe.
  • Customizable cache-miss behavior.
  • Zero third-party dependencies.

Usage

safecache preserves the functools.lru_cache's API so no extra learning is needed.

To migrate from lru_cache to safecache, you can simply rename the decorators!

Before:

from functools import lru_cache

@lru_cache(maxsize=32, typed=True)
def function(*a, **kw):
    ...

After:

from safecache import safecache

@safecache(maxsize=32, typed=True)
def function(*a, **kw):
    ...

And now you get all the benefits of lru_cache with the enhancements of safecache.

For more advanced usage of safecache, please refer to the documentations.

FAQ

License

safecache is under MIT License.