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

  • add back in ast parsing, to decorator factory
  • 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.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 dependency_cache 0.1.2
File Size Uploaded
dependency_cache-0.1.2.tar.gz 155.2 kB Details

Built distributions (wheels)

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

Total release size: 5.2 MB

Release files / dependency_cache-0.1.2.tar.gz

Download URL dependency_cache-0.1.2.tar.gz
Size 155.2 kB
Tags Source
SHA-256 checksum
How to use checksums
92c6ad329a9686c596d8f860dd63f76ba77d70c3e70790a94ee6953e981c8a98
BLAKE2b-256 checksum
How to use checksums
062a9d87364ecdf4ebec517a07071c9cedc7e4f02a539c8ecf4953ebcae4a469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.1.2-cp38-abi3-win_amd64.whl
Size 190.0 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
840a8c0f58f630323f2cae1b319c1b9084b22d9e8d871f4e246d5dabbf0ad9cc
BLAKE2b-256 checksum
How to use checksums
109d77d08016907b5e748bdb805abbbfa4f494a341e9fc271105b207ea3e3bf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

Download URL dependency_cache-0.1.2-cp38-abi3-musllinux_1_2_aarch64.whl
Size 479.1 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
e299c1cc5e974ce6090132df0870f16186013dc662187d17f93fb84d24e45f2f
BLAKE2b-256 checksum
How to use checksums
8544f0186b578b0b2716486f1ecfa0daf49e70cb370352bd9bb2c94487a1818c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 305.8 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
9a8470b7994581a9e2e4e9a39dc1bedf174689fdef25f1ff62e55ab69323589a
BLAKE2b-256 checksum
How to use checksums
5c40c495c518e3e4289fdfb7dee35d16a38e34090fad74be3ebb42cccbc606c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

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

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

Download URL dependency_cache-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
Size 275.7 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6958dca8a11f3fd94d194b43584a8cde7743a972e43d2821594238ab3db69699
BLAKE2b-256 checksum
How to use checksums
310921ddb5d4d37bdba5edf6316fb2d47ce49652de595ec60fd22225a2e89f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl
Size 285.5 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9a31d5ca48656cdd9b3dfa2deb20a265da4a5d164d0c373c6ae91d34423756f6
BLAKE2b-256 checksum
How to use checksums
50bfdf90437de0f07d0811e361354ca175672a6d967e0a585f1331b63857e2fc
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

0.1.3

15 release files

This release

0.1.2 This release

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