Skip to main content

Dependency Cache

🚧 Work In Progress 🚧

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):

  • scenario analysis capability (add temporary cache to base)
  • add validation to static dependencies, ensure methods are of decorator class
  • improve plot_dependency_graph (maybe to GUI?) with moveable nodes
  • add object thread safety for python 3.14+
  • work out how best to handle nested objects

Release files for dependency_cache 0.2.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.2.0
File Size Uploaded
dependency_cache-0.2.0.tar.gz 156.4 kB Details

Built distributions (wheels)

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

Total release size: 5.3 MB

Release files / dependency_cache-0.2.0.tar.gz

Download URL dependency_cache-0.2.0.tar.gz
Size 156.4 kB
Tags Source
SHA-256 checksum
How to use checksums
496fe93e4f3bf0f75d56302ed452fbc17f554d8dd1a19d4aa480777bab914db4
BLAKE2b-256 checksum
How to use checksums
0990160c1b21270b6b8d95f5c5026f42ba4b8ebffe7662c7340f2f5c93fbdeab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-win_amd64.whl
Size 200.1 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
40b30323ce992789967232f74f4f39b87ecebcad0d80ee9491a599a1e2583b82
BLAKE2b-256 checksum
How to use checksums
af1a953111a9d00a70a585503493234bfef64cb1cebdd0ddc0c8b659af0f67b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-win32.whl
Size 186.7 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
1945c88aa555394a5ef082d29726ea73a2a7fd2f3840f83e6f8992187335e1b4
BLAKE2b-256 checksum
How to use checksums
eec84103f10ed536987b5227cb2ddbe611ee6b25536d414f37d4c16f1540fe95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl
Size 526.7 kB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
d17619a2bb11eef48c1e12005fb13640cf8bb94bf5e654082a34b8101fd4fe32
BLAKE2b-256 checksum
How to use checksums
7fc36c9a05085c447b9e5a3210d7eb206dc9d80c19d8f9a721be6648fb6e0564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-musllinux_1_2_i686.whl
Size 556.9 kB
Tags CPython 3.8 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
95a3b71c6194343bc800d48ae78bbb95f0cb2f8c3ad151ca2c294bbc792fdf90
BLAKE2b-256 checksum
How to use checksums
fd787d4344c435fd30af6ad4b36932f3e676630cd0191199ee8fa177808ddc61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-musllinux_1_2_armv7l.whl
Size 603.3 kB
Tags CPython 3.8 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
5681c5375eb30ace54e5ff0a893920e0ebaaa3a34558aa26e60833b940f96b12
BLAKE2b-256 checksum
How to use checksums
eba111fdd60106b4993862fc2af10e368466e192ea52f0d6f81043992d285360
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-musllinux_1_2_aarch64.whl
Size 486.7 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
71b20066b98e1076c64c59aea910b3135fb76f0e573758334758b98033fcc7b3
BLAKE2b-256 checksum
How to use checksums
94a07bbd2f62e543aa255ba69c2c05bba51a3b3af502ef45f04d8f47d736fd31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 314.2 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
53b202c2daf49329659c0442a0deebcb094690eede2fd35db64b9f76a8fa504f
BLAKE2b-256 checksum
How to use checksums
05bcef6f54bc744b1ff54515b6bc188a5da53beefe72cfa1e5ec32c9e83853eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

Download URL dependency_cache-0.2.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 345.2 kB
Tags CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
ef21e4f25ad9a67466b43f488e4e459a92195a9b89d1dc67f456a243e6de2206
BLAKE2b-256 checksum
How to use checksums
38949abe373472da44342c6e2dd7b2ffc47470885cb9f59e217ca45bfc411a0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 326.3 kB
Tags CPython 3.8 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
b792454ed53e82edbb2f793d28426dfec837afdc552ea42845f4f683b6c24566
BLAKE2b-256 checksum
How to use checksums
65dd6a3f1b26ac587df8884d8155aa84b4e9116c75754cc831b222e2cb83ef24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 307.6 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2756c8ba52a25667467bc8f17ade8665f1f511110525d0f1aeba4b914b16e9b9
BLAKE2b-256 checksum
How to use checksums
566d88d4ed01694686b9ba9b8dc78cf5cf1b6b7c945687bb30cfa048a11e3e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Size 338.7 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
ecc1c1bf0fc534ac721b8c504562e2bffb5eddc223e21e796bf7fa7913296d3f
BLAKE2b-256 checksum
How to use checksums
95bc68541c29621e393c57b908c9000ce8d41aeea27a112ce47c647176be6795
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
Size 284.8 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0c7b1ce19f0bc07206099870b7c1632407478414ca31419c85bc77dc7d0744a7
BLAKE2b-256 checksum
How to use checksums
72cda4e566d0d5d1d38e77aebe74d5c7a2c2cfcaafc6caceb635fa0d9f6f9996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 294.4 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9c2a49e55980e050919ee47272f6bcdc7e157a7c2eb4e8adeca33e30375cad58
BLAKE2b-256 checksum
How to use checksums
d8bab36c69045de26c6bb1191e91635d6ec2cf1d5b5381e6cfe0e35474001dc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

This release

0.2.0 This release

15 release files

0.1.3

15 release files

0.1.2

15 release files

0.1.1

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