Install & Compatibility
Where this runs
tested against v1.6.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.340s · 18.4MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.274s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
cached_property
✓ from property_cached import cached_property
✗ from property_cached import cached_property
This example demonstrates how to use `cached_property`. The `loaded_data` property will execute its computation only on the first access for a given `MyResource` instance. Subsequent accesses retrieve the cached value. It also shows how to explicitly delete a cached property to force re-computation if the underlying state changes.
from property_cached import cached_property
import time
class MyResource:
def __init__(self, name):
self.name = name
self._heavy_computation_count = 0
@cached_property
def loaded_data(self):
print(f"[{self.name}] Performing heavy computation for data...")
time.sleep(0.1) # Simulate delay
self._heavy_computation_count += 1
return f"Data for {self.name} (computed {self._heavy_computation_count} times)"
resource1 = MyResource("Resource A")
print(f"First access: {resource1.loaded_data}")
print(f"Second access: {resource1.loaded_data}") # Will not re-compute
print("\nModifying resource, then trying to access again...")
# If underlying state changes, the cached property remains stale
resource1.name = "Resource A (modified)"
print(f"Access after name change: {resource1.loaded_data}") # Still uses old cached value
print("\nDeleting cached property to force re-computation...")
del resource1.loaded_data
print(f"Access after deletion: {resource1.loaded_data}") # Re-computes with new name
Debug
Known issues
gotchaThe `cached_property` decorator caches the result indefinitely for the lifetime of the instance. If the underlying data or state used to compute the property changes, the cached value will become stale. It will not automatically re-evaluate.fixTo force re-evaluation of a cached property, you must explicitly delete the attribute from the instance, e.g., `del instance.property_name`. The next access will then trigger re-computation and cache the new result.
affects: All versions
breakingThis library is a fork of the original `cached-property`. If migrating from the original library, ensure all import statements are updated to `from property_cached import cached_property` to avoid mixing implementations or using an outdated version.fixReview your codebase and replace all instances of `from cached_property import cached_property` with `from property_cached import cached_property`.
affects: N/A (migration scenario)
gotcha`cached_property` is designed for properties (methods taking only `self`). It will not work correctly as a general-purpose memoization decorator for methods that require additional arguments.fixOnly apply `@cached_property` to methods that function as properties, i.e., they take no arguments other than `self`. For memoizing methods with arguments, consider a different library or a custom memoization decorator.
affects: All versions
Upgrade
Version history
1.6.4latest on PyPI · released Mar 6, 2020
Audit
Dependencies
No dependency data recorded yet.