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.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dependency_cache-0.1.3.tar.gz | 155.2 kB | Details |
Built distributions (wheels)
Total release size: 5.1 MB
Release files / dependency_cache-0.1.3.tar.gz
| Download URL | dependency_cache-0.1.3.tar.gz |
|---|---|
| Size | 155.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80c451b7e4f1f68947d73cf07c9a526601f53c6f6b979c1c01f812eecfae389d
|
|
BLAKE2b-256 checksum How to use checksums |
6b6cac59d0d3a514dc4985c15e48572dc69dababa33739990e646b8759ace069
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-win_amd64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 186.7 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
432701d353a4ddc0c901d38c0ebabc5e262ae3861d938bf6595b31741b95d68b
|
|
BLAKE2b-256 checksum How to use checksums |
b10d4a78b393ddb2e9808861beab04a4678c915a6663ef2448b60493a9cb21c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-win32.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-win32.whl |
|---|---|
| Size | 176.8 kB |
| Tags | CPython 3.8 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
f78a3ea1d09168b04359e28057709f03ab832d44e46ed9652542f4cb453e1db3
|
|
BLAKE2b-256 checksum How to use checksums |
6bada1cbb4165a70632954bea99f4f905a53819c1deb8fe6754562c10445952b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 513.6 kB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
87b588fafbafd1bc95f3db68d5f68d537fc9f1426b99bb78f739409fcabded4b
|
|
BLAKE2b-256 checksum How to use checksums |
532587aba040c3b0ad88e4436faa99b77e9ae71169cce42dd71c4bc4f30673e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_i686.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 544.4 kB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
4173ce7940cb3d8a65fdec4f11bec6ec28cd3f51c9c53d1504f7d4edebb84ebb
|
|
BLAKE2b-256 checksum How to use checksums |
a372accc7a06cee3f4bb6ad4e8aa436ead4049d9437e930c17f24d4646ad01a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 592.1 kB |
| Tags | CPython 3.8 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
57d7613d66eb4a3a2241a8480178b634a0c2aac796da18fdd2b742a2c9bf6d4e
|
|
BLAKE2b-256 checksum How to use checksums |
0e325507d8c68d8e9185e5f3327b59fb908c8ebd3733e1c9ed8903a9cf73dae6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 475.3 kB |
| Tags | CPython 3.8 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
94e2b07ed7be8a89d5e894cbfd0e10acd7cb2765310b18ab5ea43739b348296d
|
|
BLAKE2b-256 checksum How to use checksums |
62178a786457c2e492b44eac2f2777372824a64500a2cc0e5b4fa0a2fba061bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 302.0 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
36c956cd0e7a8024305c7707d5f7c060dd8f4e1f7e0e43a670d21c130d6f2bb7
|
|
BLAKE2b-256 checksum How to use checksums |
f2d1f7b634c916934c4be8e783ba6bc50cb530465c30b3219dbdf905282748bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 335.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
164479794ee27053ca1ea7b8934653f9ade74088e86c2ad047f957467ac05701
|
|
BLAKE2b-256 checksum How to use checksums |
9774e350e04361f45c84eb746046988fc1f34c9bd9bd2271628404fde0d6281b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 332.4 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
9c821ef11834caf0d2d0d0db4e9ef49eabda54b11ae8db527af084c793b220da
|
|
BLAKE2b-256 checksum How to use checksums |
20fe9ed1e3b43b4c0a3f45d3e786ab80b2c8192f46c7a1e0a2321b8fba371dcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 314.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
7e10c1b0d3288d5dfdad7c12c00b16a4f4de29a2db2d31efca7e271386f41473
|
|
BLAKE2b-256 checksum How to use checksums |
10944840d0ddb122ed3564d32c63f3b74f0df9a98b784242c4658831087b0691
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 297.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b2ae5f7f6af0e6ad2a8d9ef56a6f0001e1cfefe67b0c2a2ee1d11394105d1ab9
|
|
BLAKE2b-256 checksum How to use checksums |
20c421ec7a5aa203f9e5c1f4b7aed62efa20f9002906291def54deddc64c9075
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 327.8 kB |
| Tags | CPython 3.8 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
b2fda69a7baa772978134d47c0f9e3ee8581854654e17d3e7d03c38194a758f9
|
|
BLAKE2b-256 checksum How to use checksums |
8d94099bccbbd4b5a09a9882af186c443279e86f539bd412314c88eb2225e68e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 271.8 kB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4f4a5c9b202e3697de8499b5398506d45abcfd22c184e96632cf7ed3aa86c1d4
|
|
BLAKE2b-256 checksum How to use checksums |
dab3459b9b76293a3a732f3c42bb083f72bdbd648633c335a95fba708d0a63e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / dependency_cache-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | dependency_cache-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 282.9 kB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
d1817b5c42d97161e878aa7b96df12dd405660e6c879d0df914cba8f2e49ed41
|
|
BLAKE2b-256 checksum How to use checksums |
979a88ca5252e040ca9ddd700952ee5d0dcd46c1e91a5a6a0e5da64b1accde22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|