Skip to main content

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
# Alternatively you may use the lowercased name
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)

Metadata

Release files for dyncache 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dyncache 0.1.2
File Size Uploaded
dyncache-0.1.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dyncache 0.1.2
File Interpreter ABI Platform
dyncache-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / dyncache-0.1.2.tar.gz

Download URL dyncache-0.1.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6ff39bc33488787001667c91fc7556dc035c7891a219fa2b1623d1a92897c422
BLAKE2b-256 checksum
How to use checksums
630647f072d2d098ce7ae4e0fc241d2cafc65e49168d6396e4c26c79c2194ed1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Linux/6.12.6-zen1-1-zen

Release files / dyncache-0.1.2-py3-none-any.whl

Download URL dyncache-0.1.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1fac4eac0457a7b48c8685efcc204a9244e3ae216a0e2438689d421248bc742
BLAKE2b-256 checksum
How to use checksums
ad659fbeed5e0e4b58c877e9069c5fec18a03939c3bf39f20657d5e833a9bb57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Linux/6.12.6-zen1-1-zen

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page