cachegrab
cachegrab is a Python package that provides decorators for caching instance methods.
Installation
pip install cachegrab
Main Features
deep_cached_property➔ Inspired by functools' cached_property, this decorator provides a deep copy of cached return values, ensuring they remain immutable after their initial access. The original return values are preserved in a dictionary namedself._deep_cache.protected_attribute➔ Decorator that returns the protected attribute corresponding to the name of the decorated function. If the protected attribute does not exist, it sets the attribute to the return value of the decorated function.
Example Usage
Imports
from cachegrab import deep_cached_property, protected_attribute
from functools import cached_property
Decorate Instance Methods
Consider the example class Dog below:
toys➔ decorated withcached_propertybecause toys can be buried and are therefore mutable.is_good_boy➔ decorated withdeep_cached_propertybecause his good boy status is never in question.tricks➔ decorated withprotected_attributeto prevent direct overwrites.
class Dog(object):
@cached_property
def toys(self):
return {'ball','bone'}
@deep_cached_property
def is_good_boy(self):
return True
@protected_attribute
def tricks(self):
return {'sit','shake'}
def bury_toys(self):
while self.toys:
self.toys.pop()
We will attempt to modify both cached properties:
dog = Dog()
dog.bury_toys()
dog.good_boy = False
Let's look at the results:
print('dog toys ➜', ', '.join(dog.toys) if dog.toys else '?')
print('good boy? ➜', dog.is_good_boy)
print('_deep_cache ➜', dog._deep_cache)
dog.tricks # access tricks property
print('_tricks ➜', dog._tricks)
dog toys ➜ ?
good boy? ➜ True
_deep_cache ➜ {'is_good_boy': True}
_tricks ➜ {'sit','shake'}
Metadata
Release files for cachegrab 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cachegrab-0.2.4.tar.gz | 17.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cachegrab-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.8 kB
Release files / cachegrab-0.2.4.tar.gz
| Download URL | cachegrab-0.2.4.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2269c2c34d3b91a779239bb4eca6b7725ea1ec1ece52bf5d7658666abb2684bd
|
|
BLAKE2b-256 checksum How to use checksums |
8e638a2421fbf2bb7c16e8e695b655640338d12c885a3d3c7c167c94c233d56b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / cachegrab-0.2.4-py3-none-any.whl
| Download URL | cachegrab-0.2.4-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b08c877d8ebd76bda69a7dc266026d1c46c9a9075b6c1072eb316cab0c64678a
|
|
BLAKE2b-256 checksum How to use checksums |
7c90ca31b958e36a0cf8a1040996e9ff569e72cb2e5126f60fe77d952c0ecfed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for cachegrab 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.