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.

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 :gun: decorator for a method where you explicitly declare direct dependencies.
automagically_dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=True) A decorator which automagically infers the direct dependencies with the option to override manually using dependencies=.
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.0

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.0
File Size Uploaded
dependency_cache-0.1.0.tar.gz 153.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dependency_cache 0.1.0
File
dependency_cache-0.1.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
dependency_cache-0.1.0-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
dependency_cache-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
dependency_cache-0.1.0-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
dependency_cache-0.1.0-cp38-abi3-musllinux_1_2_armv7l.whl CPython 3.8 abi3 Linux musl 1.2+ ARMv7l Details
dependency_cache-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
dependency_cache-0.1.0-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.0-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.0-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.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details
dependency_cache-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
dependency_cache-0.1.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.8 abi3 Linux glibc 2.5+ x86-32 Details
dependency_cache-0.1.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
dependency_cache-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.8 MB

Release files / dependency_cache-0.1.0.tar.gz

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

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

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

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

Download URL dependency_cache-0.1.0-cp38-abi3-win32.whl
Size 158.8 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
b02ec58ee329748502098419af5ac7a08baf03438fef5e29d3e8810931eeaceb
BLAKE2b-256 checksum
How to use checksums
819068031285a1e2e324da497afff79c07ade6dc2598732eac6b0519feae9854
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

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

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

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

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

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

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

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

Download URL dependency_cache-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl
Size 457.9 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
1487020897155b538eb97ad2a92f8e394d905ae20b2f52164f454af6066373b4
BLAKE2b-256 checksum
How to use checksums
0ef107915f43b7a78605150b8ca52296e43f06531ae484bd0cca54ad2a71af71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

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

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

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

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

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

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

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

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

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

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

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

Download URL dependency_cache-0.1.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Size 306.3 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
655cafb8017e6bd156942b289579786eef729fe49d668d4ac1f3e8b96351bb96
BLAKE2b-256 checksum
How to use checksums
13793f98d64da1d7df91d90a7695a57331019bab55074e2cfe7b9df553fc1f54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

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

Download URL dependency_cache-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Size 257.7 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
337d9ae3560d464fba1194dba9dedf179cf2f343765c9483ec997551c932c960
BLAKE2b-256 checksum
How to use checksums
eb03fb8c90d58a243487334120b8ea706dc7e243415c0c110b22dc875d9708fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

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

Download URL dependency_cache-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 263.4 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
36efdf0295fea98fc29d7d182cf23500b5c69e7fe4f846fde6eb65d64f191623
BLAKE2b-256 checksum
How to use checksums
60feb4ab5fbf85a1ac65167f0b62ea2cd09b80580557692cfa1d3504912303fa
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

0.1.1

15 release files

This release

0.1.0 This release

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