reckon: Dead simple, dynamic caching.
Project description
reckon: Dead-simple, dynamic memoization
Installation
In order to install the latest version, simply pip3 install -U reckon
.
This library requires Python 3.6 or greater.
What is it?
reckon
implements a dynamic LRU cache by automatically
monitoring the memory usage of your machine and purging
entries as it approaches a pre-defined ratio (defaults to
90%).
reckon
is largely inspired by the global_lru_cache
package, so credit should be given for the initial
implementation. This package brings those ideas into python3
and adds a local cache implementation as well.
Usage
Usage is simple:
import reckon
@reckon.memoize
def some_expensive_func(foo: int, bar: int):
return foo ** bar
reckon
will automatically make use of the global cache.
While the global cache is automatically maintained, it may be necessary to managed the cache manually. To that purpose, reckon provides the following global methods:
reckon.glob.clear
: Clear the global cache.reckon.glob.shrink
: Shrink the global cache.reckon.glob.usage
: Check the current usage ratio.reckon.glob.set_usage
: Set the max memory usage ratio for the global cache.
If you wish to only maintain a cache local to a function you can simply pass a flag to the decorator:
import reckon
@reckon.memoize(locale="local")
def some_expensive_func(foo: int, bar: int):
return foo ** bar
Additionally, if you wish to maintain a cache local to a
module, you can initialize your own instance of the
LocalCache
object:
import reckon
cache = reckon.local()
@cache.memoize
def some_expensive_func(foo: int, bar: int):
return foo ** bar
The local cache instance maintains the same high-level API for management as the global cache:
LocalCache.clear
: Clear the local cache.LocalCache.shrink
: Shrink the local cache.LocalCache.usage
: Check the current usage ratio.LocalCache.set_usage
: Set the max memory usage ratio for the local cache.
Documentation
Full documentation coming soon!
How to Contribute
- Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
- Create a branch on Github for your issue or fork the repository on GitHub to start making your changes to the master branch.
- Write a test which shows that the bug was fixed or that the feature works as expected.
- Send a pull request and bug the maintainer until it gets merged and published. :)
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
Built Distribution
File details
Details for the file reckon-0.1.1.tar.gz
.
File metadata
- Download URL: reckon-0.1.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 744dd92d14396ce16262c6c6aa8054e1c0b866e077d3c6899f42eee5a765a894 |
|
MD5 | 21287c3fdffeb8e3432c4b7b3f152188 |
|
BLAKE2b-256 | a14e101505af9331b5dd8de7dbaf8ea6e1adc4dc46154e89b2264aa779920866 |
File details
Details for the file reckon-0.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: reckon-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96668cf661779afbfc65a5b519abe0628fe942bc77e7a4009a05f4c4518049db |
|
MD5 | d5d92a803dda38fe86596c534827c5ff |
|
BLAKE2b-256 | 39d1d4f02bea5f7fd6c3899192ea5bd16ee5629b1121f8aa2c1aad38edf358dd |