Skip to main content

reckon: Dead simple, dynamic caching.

Project description

reckon: Dead-simple, dynamic memoization

image image image image image codecov Code style: black

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

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Create a branch on Github for your issue or fork the repository on GitHub to start making your changes to the master branch.
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. 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

reckon-0.1.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

reckon-0.1.2-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file reckon-0.1.2.tar.gz.

File metadata

  • Download URL: reckon-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 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

Hashes for reckon-0.1.2.tar.gz
Algorithm Hash digest
SHA256 dd116c3eee5fbd3d3aab0fbabb11fcb8ad939e7a7bef18be26b59a977c939a1b
MD5 f5bc50596796117ea80b5eb7d53f0e83
BLAKE2b-256 e5a0a494db58e0a1b6f94b4a5e40a821514e6e4cad96bd6b71a6bcaa0e4f4445

See more details on using hashes here.

File details

Details for the file reckon-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: reckon-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.3 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

Hashes for reckon-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d1d91dfd338b95e91b76808641bc37fb8c12b7c5ae9cc116ba96a18ee0ab5d38
MD5 12164ae504e7235aa00bcf3eeb150ff8
BLAKE2b-256 d9e3b800b9998837599dc64447e371abc241f4c3a8b806a02af9c918e1f4df22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page