A Multiton pattern implementation with TTL-based cache expiry
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
rarg-multiton
A small, self-contained implementation of the Multiton pattern with TTL-based cache expiry.
A Multiton wraps a factory function and its arguments. The underlying
instance is created lazily on first access to .instance and cached, keyed on
the (frozen, hashable) factory and arguments. Any Multiton constructed with
the same factory and arguments shares the cached instance. Multiton objects
are themselves hashable, equality-comparable and pickleable (with pickle,
cloudpickle and dill), provided their arguments are too.
Cached instances expire after ttl seconds of inactivity; accessing
.instance resets the TTL. Expired entries are swept on every access via a
min-heap ordered by expiry time.
from rarg_multiton import Multiton
def open_connection(url: str, timeout: float = 1.0) -> Connection:
...
# The resource is only created when `.instance` is first accessed.
resource = Multiton(open_connection, "https://www.python.org", timeout=10.0)
response = resource.instance.request("GET", "/foo/bar.html")
# Override the default TTL (300s) per-instance.
resource = Multiton(open_connection, "https://www.python.org").with_args(ttl=60.0)
Installation
pip install rarg-multiton
The package has no required runtime dependencies. numpy is an optional
dependency: when installed, numpy.ndarray factory arguments are frozen by
their bytes, shape and dtype so they can be used as cache keys.
Development
This package uses uv.
uv sync
uv run --group test py.test tests/
uv run --dev pre-commit run -a
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rarg_multiton-0.0.1.tar.gz.
File metadata
- Download URL: rarg_multiton-0.0.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31d0b4de55211d3ee4a1671ec978cb102599ee2e33884c6b874824de8a9b4fc2
|
|
| MD5 |
3189258e362cbf731dcad5394be00f27
|
|
| BLAKE2b-256 |
91c52ec18cb903e44c124daf25f68a2a21f13a10d1379ec856ca4001d5cf8dcd
|
Provenance
The following attestation bundles were made for rarg_multiton-0.0.1.tar.gz:
Publisher:
ci.yml on ratt-ru/rarg-multiton
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rarg_multiton-0.0.1.tar.gz -
Subject digest:
31d0b4de55211d3ee4a1671ec978cb102599ee2e33884c6b874824de8a9b4fc2 - Sigstore transparency entry: 1719493775
- Sigstore integration time:
-
Permalink:
ratt-ru/rarg-multiton@89fa9c1a63bc83b700e091252ede632e1bfae8fa -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/ratt-ru
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@89fa9c1a63bc83b700e091252ede632e1bfae8fa -
Trigger Event:
push
-
Statement type:
File details
Details for the file rarg_multiton-0.0.1-py3-none-any.whl.
File metadata
- Download URL: rarg_multiton-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
894dee6a1eafdfc0b525679c07a5188148091f50cab6abd75d4c92afc73771be
|
|
| MD5 |
9ca18d914097219575f251cbc0a7826a
|
|
| BLAKE2b-256 |
1616d89e7d7c27ef338fd46746cf4f56638a51fff041def5ccd10b649449fb35
|
Provenance
The following attestation bundles were made for rarg_multiton-0.0.1-py3-none-any.whl:
Publisher:
ci.yml on ratt-ru/rarg-multiton
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rarg_multiton-0.0.1-py3-none-any.whl -
Subject digest:
894dee6a1eafdfc0b525679c07a5188148091f50cab6abd75d4c92afc73771be - Sigstore transparency entry: 1719493922
- Sigstore integration time:
-
Permalink:
ratt-ru/rarg-multiton@89fa9c1a63bc83b700e091252ede632e1bfae8fa -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/ratt-ru
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@89fa9c1a63bc83b700e091252ede632e1bfae8fa -
Trigger Event:
push
-
Statement type: