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

  • scenario analysis capability
  • allow input to control ordering for cache dump
  • 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.4

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.4
File Size Uploaded
dependency_cache-0.1.4.tar.gz 155.6 kB Details

Built distributions (wheels)

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

Download URL dependency_cache-0.1.4.tar.gz
Size 155.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3cbecfd1d7d3633ccc6b52bda1c435ba4834a02a162c4e2bd56c54f65d6c35bd
BLAKE2b-256 checksum
How to use checksums
b3b495a550e09c9c2f2d59a2e179a964c51b851a01db9ff364af41e8ba704d26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

Download URL dependency_cache-0.1.4-cp38-abi3-musllinux_1_2_armv7l.whl
Size 597.8 kB
Tags CPython 3.8 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
620825456c290be0d62b9a7007527e6647f3f1077ea4e8973082aecfaadcd13e
BLAKE2b-256 checksum
How to use checksums
03f4b7354ff8b1c06e91d45b4bfac3eaee38db93b0b98431594c86e2a72fa5ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

Download URL dependency_cache-0.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 308.7 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1c6436acf734c2418861fccedca49e39784ace6740754c3e30afd8d59fc06f8c
BLAKE2b-256 checksum
How to use checksums
6c3a340925d8329928b4d1c759a8d33a5eda1ca1d10ebba57642e2d9bbbc989b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

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

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

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

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

Download URL dependency_cache-0.1.4-cp38-abi3-macosx_10_12_x86_64.whl
Size 288.9 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
178f2db818e54f7b968d82c68f4a275b58c93d9f47a0ccdf5d51610a014354b4
BLAKE2b-256 checksum
How to use checksums
83de6957ce0faa3f0bb4cb16cf47e49c0f1c7dea80dd6257a2796c5dc52d8faf
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.1.4 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