Skip to main content

Dependency Cache

:construction: Work In Progress :construction:

Description

A library for managing the caching of an object's methods with cache invalidation handled by a dependency graph. Instead of recomputing expensive, deeply nested calculations on every call, Dependency Cache stores the result and only invalidates (and recalculates) it when one of its dependencies actually changes. This project is written in rust, with pyo3, and compiled using maturin.

Installation

Install the latest stable version from PyPI:

pip install dependency-cache

API Overview

Export What it's for
DependencyCacheBase Base class to inherit from. Gives your instance a cache and a dependency graph.
dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=False) A footgun-enabled decorator for a method where you explicitly declare all direct dependencies.
automagically_dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=True) A decorator which automagically infers the direct dependencies. Optionally override the defaults and inference using the dependencies parameter.
plot_dependency_graph(obj, **kwargs) Visualizes an instance's dependency graph, for inspection/debugging.

Setup

This project uses (and requires) uv as a package manager and maturin to compile.

Steps:

  • install python dependencies
uv sync
  • generate local development file for testing (and update pyi file for accurate typechecking)
maturin develop --generate-stubs
maturin develop -r --generate-stubs
  • run python tests
uv run pytest
uv run pytest -vv
  • run rust tests
cargo test
  • temporary fix: generate stubs currently produces a file that is incorrectly formatted, use ruff to format the pyi file immediately
maturin develop --generate-stubs | uv run ruff format ./python/dependency_cache/dependency_cache.pyi

Quick Example

from dependency_cache import DependencyCacheBase, automagically_dependency_cached


class ExampleCalculation(DependencyCacheBase):
    """   C
        //  \\
       A      B
    """

    def __init__(self, x, y):
        super().__init__()
        self.x = x
        self.y = y

    @automagically_dependency_cached()
    def A(self):
        print("calculating A")
        return self.x

    @automagically_dependency_cached()
    def B(self):
        print("calculating B")
        return self.y

    @automagically_dependency_cached()
    def C(self):
        print("calculating C")
        return self.B() + self.A()


c = ExampleCalculation(3, 5)
print(c.C())  # calculates A, B, C -> 8
print(c.C())  # hits cache -> 8

c.update_cached_value("A", 0)  # invalidates C (but not B)
print(c.C())  # recalculates C -> 5

This example can be found here with more runnable examples and use cases provided in the python/examples folder.

uv run ./python/examples/example.py

TODOs

This project is still a work in progress, with everything from API to underlying design subject to change on my whim.

Current TODO list (in no particular order):

  • load and dump cache methods for base class
  • add back in ast parsing
  • move plot_dependency_graph to rust side instead of python
  • add object thread safety for python 3.14+
  • work out how best to handle nested objects

Release files for dependency_cache 0.1.1

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

Source distribution (sdist)

Source distribution for dependency_cache 0.1.1
File Size Uploaded
dependency_cache-0.1.1.tar.gz 154.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dependency_cache 0.1.1
File
dependency_cache-0.1.1-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
dependency_cache-0.1.1-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_armv7l.whl CPython 3.8 abi3 Linux musl 1.2+ ARMv7l Details
dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.8 abi3 Linux glibc 2.17+ IBM System/390x Details
dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.8 abi3 Linux glibc 2.17+ PowerPC 64-le Details
dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details
dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
dependency_cache-0.1.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.8 abi3 Linux glibc 2.5+ x86-32 Details
dependency_cache-0.1.1-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
dependency_cache-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.0 MB

Release files / dependency_cache-0.1.1.tar.gz

Download URL dependency_cache-0.1.1.tar.gz
Size 154.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f03f98fd737924c612e7ae8026c95498982245505c2475ae5c636718dfded2a9
BLAKE2b-256 checksum
How to use checksums
e6545fdd0c475b8c36bbd9c6ddfd584e3a4dd27af38f878e1a29ed34ff2529c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-win_amd64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-win_amd64.whl
Size 179.2 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f12fb330b72a278373c17b56cbf23a6ad46ad66b1e422a169862019ec9cc2ba6
BLAKE2b-256 checksum
How to use checksums
02632d4a323b30b0b4a2fdf6f3d5867a44737ddef244d56cc39df5a7f99ed0ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-win32.whl

Download URL dependency_cache-0.1.1-cp38-abi3-win32.whl
Size 169.4 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
481643282d5c0794deda30701914e41b402d617a268ab2dd34d92c321c91a2b5
BLAKE2b-256 checksum
How to use checksums
01ce515c976ca7a6d24be850cc3b883a1c735465530907e4cef08c0cb6784ad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_x86_64.whl
Size 506.8 kB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
caaf23ed80b53b219c3347983d2e0bd5d50150daccddcf5248b903b1c7b79b6d
BLAKE2b-256 checksum
How to use checksums
2ffd02fe34e357ae71a3f3921427bbebd010f515f742e630ce2824161f7df7cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_i686.whl

Download URL dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_i686.whl
Size 537.2 kB
Tags CPython 3.8 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
de6a966be6a95e83be6588a273fa723616af569626728d2016fbff2b5676bd12
BLAKE2b-256 checksum
How to use checksums
3e84b153b29dff7686a12b80d201e6a02de9a4bf3c3bba208cdc8d4cfdef0661
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_armv7l.whl

Download URL dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_armv7l.whl
Size 587.4 kB
Tags CPython 3.8 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
8f89866cff2d508ea011f79c92105598a1ec4d1f590ceebd26a429e06c2ee1b4
BLAKE2b-256 checksum
How to use checksums
77c9014d59b45bd0a1f011e114d8074958a3a525e21fc73364ff3bef4c9d87bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_aarch64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-musllinux_1_2_aarch64.whl
Size 466.8 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
79038888f37d875e4e8005f42ba57333292244e0b49935086029cee5c3b1fb40
BLAKE2b-256 checksum
How to use checksums
5ba356ea76d7b341bdac4d79af652f7d0e96f445b34a965168029ba76f31c4ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 294.6 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0663225fe541ab5798c512810ad5b9b5a329b271e83a83b93d605d1a1555fc76
BLAKE2b-256 checksum
How to use checksums
f52bfa57311ef5d48fd9a6d5822490125365786326d9058d8dbae1d03a25e196
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 328.3 kB
Tags CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
106fc3fe4fbc913a65dafb605719751ed0cef3873da2e8cbecb5f1116943acc5
BLAKE2b-256 checksum
How to use checksums
e78c82faf2b23f8f9ff17ed478d25bff5bd4f5c86d02825bdcb90203780dfc8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 325.8 kB
Tags CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
28a80ecc43218c9e9a0f95bdd6247282869414a2a21d5d37d9e1870e1a5c43e5
BLAKE2b-256 checksum
How to use checksums
6f5f1b1aedb45392df2395779b8c327db96cad3ed8ca12edfdc4fccaede46b9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 309.6 kB
Tags CPython 3.8 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
ba0e8245efea209c971f8a270e4ed015708ea9535b945c15556ae6962c337c81
BLAKE2b-256 checksum
How to use checksums
1f0eda0abdf282af0ba94d8abb685968dd4b4aa0a37288d520dda24fa90539b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 287.8 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
fdec7f10d110ac3352e528539e0b7dc13c3614942da792095d11e5161504311b
BLAKE2b-256 checksum
How to use checksums
137449aa5a45465b237d511d4040c980b2ff805e7a7efbe54a8140373eca36c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl

Download URL dependency_cache-0.1.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Size 319.5 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
72e773602d0de92bdfc635ee2a27e0cdffe5922fd58117c3d4f4569f58601adb
BLAKE2b-256 checksum
How to use checksums
6e8d42b71b7844b8dc3cb3426db2dd616c65f4bf59aba86daec6522ec4d041b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-macosx_11_0_arm64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
Size 267.7 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
26a6cf4e3051c9bf7482031c0ea08407c48f7430341b16f1c1cfe1f9c7678803
BLAKE2b-256 checksum
How to use checksums
8285c8430e0cd148a6a86d33b3710692b1a192ef2f67c0a728371b72f5414b4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / dependency_cache-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl

Download URL dependency_cache-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl
Size 275.9 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
45435898841756646f090660da1f29dfb95686036eb53bc4ce5d81830dd9224f
BLAKE2b-256 checksum
How to use checksums
34ef74ee343dd5b1d24e1447a1e14d79aecf13712767fb75164d66cba894e8e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release history Release notifications | RSS feed

0.4.1

31 release files

0.4.0

31 release files

0.3.0

31 release files

0.2.4

31 release files

0.2.3

31 release files

0.2.2

15 release files

0.1.3

15 release files

0.1.2

15 release files

This release

0.1.1 This release

15 release files

0.1.0

15 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