Skip to main content

Dynamic input-output caching for deterministic functions

Project description

Dynamic input-output caching for deterministic functions

PyPI Read the Docs License

Features

  • Keep It Simple, Stupid: A single decorator that does everything for you

  • Automagically detects if the decorated function is changed and transparently updates cache accordingly without ever returning cached results of the old function.

Installation

pip3 install dyncache

Examples

# Import the class
from dyncache import Cache


# Use with default options. It will create a file "circle_area.dyncache" into
# the current directory.
@Cache()
def circle_area(radius):
    return 3.14159 * (radius ** 2)


# Empty parentheses are not required for the decorator.
@Cache
def circle_area(radius):
    return 3.14159 * (radius ** 2)


circle_area(2)  # Calculates and returns
circle_area(3)  # Calculates and returns
circle_area(2)  # Returns from cache


# Saves the cache to /tmp/hello.world.
@Cache(root="/tmp", filename="hello.world")
def circle_area(radius):
    ...


# Use for function with large input/output -values.
@Cache(largeitems=True)
def load_all_api_data_for_a_day(day):
    ...


# When items are small and cache would update too often, setting autowrite to
# False lets you control when the cached data is written to the file.
cache = Cache(autowrite=False)
@cache
def really_frequent_function(a, b):
    ...
...
cache.write()  # Write cache data to the file
sys.exit(0)

Contributing

  • Send any issues to GitHub’s issue tracker.

  • Before sending a pull request, format it with Black (-Sl79)

  • Any changes must be updated to the documentation

  • All pull requests must be tested with tox (if you are using pyenv, add the installed versions for py35-py38 and pypy3 to .python-version at the root of this repository before running tox)

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

dyncache-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

dyncache-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file dyncache-0.1.1.tar.gz.

File metadata

  • Download URL: dyncache-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.6.3-zen1-1-zen

File hashes

Hashes for dyncache-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae6e8c4fdad8dc04003bf5ad1011ac42b9123b1cabcea72908739ae5a6f4a761
MD5 c5e7641c0273a149f8d37e68042bea6d
BLAKE2b-256 af5ac19422aca8d88244ba7cfe54ed463b78c712b5e54a6dee06e1306e730bac

See more details on using hashes here.

File details

Details for the file dyncache-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dyncache-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.6.3-zen1-1-zen

File hashes

Hashes for dyncache-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4474789165136f99005b4bc0031b0358cd5ba264b97f2428ffd77605596e66d
MD5 4e080947db26d6c4970bea45cbd9eead
BLAKE2b-256 d78124c0f5ea0672f2cc87064139f30df2d11051e067b18078de5df5242bdbc9

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