{"id":8448,"library":"property-cached","title":"Property Cached","description":"The `property-cached` library (version 1.6.4) provides a Python decorator to cache the result of a class property's first access. Subsequent accesses to that property on the same instance retrieve the cached value without re-computation. It is a maintained fork of the original `cached-property` library, offering improved compatibility and type hinting support for modern Python versions. Releases are typically driven by bug fixes and compatibility updates.","status":"active","version":"1.6.4","language":"en","source_language":"en","source_url":"https://github.com/althonos/property-cached/","tags":["property","cache","decorator","performance","optimization"],"install":[{"cmd":"pip install property-cached","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"This library is a fork. Ensure you import from `property_cached` not the original `cached_property` if you intend to use this package.","wrong":"from cached_property import cached_property","symbol":"cached_property","correct":"from property_cached import cached_property"}],"quickstart":{"code":"from property_cached import cached_property\nimport time\n\nclass MyResource:\n    def __init__(self, name):\n        self.name = name\n        self._heavy_computation_count = 0\n\n    @cached_property\n    def loaded_data(self):\n        print(f\"[{self.name}] Performing heavy computation for data...\")\n        time.sleep(0.1) # Simulate delay\n        self._heavy_computation_count += 1\n        return f\"Data for {self.name} (computed {self._heavy_computation_count} times)\"\n\nresource1 = MyResource(\"Resource A\")\nprint(f\"First access: {resource1.loaded_data}\")\nprint(f\"Second access: {resource1.loaded_data}\") # Will not re-compute\n\nprint(\"\\nModifying resource, then trying to access again...\")\n# If underlying state changes, the cached property remains stale\nresource1.name = \"Resource A (modified)\"\nprint(f\"Access after name change: {resource1.loaded_data}\") # Still uses old cached value\n\nprint(\"\\nDeleting cached property to force re-computation...\")\ndel resource1.loaded_data\nprint(f\"Access after deletion: {resource1.loaded_data}\") # Re-computes with new name\n","lang":"python","description":"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."},"warnings":[{"fix":"To 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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review your codebase and replace all instances of `from cached_property import cached_property` with `from property_cached import cached_property`.","message":"This 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.","severity":"breaking","affected_versions":"N/A (migration scenario)"},{"fix":"Only 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.","message":"`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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install property-cached`","cause":"The `property-cached` library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'property_cached'"},{"fix":"Ensure the decorator is correctly placed directly above the property method, for example: `@cached_property\\ndef my_property_name(self): ...`","cause":"This error often occurs if the `@cached_property` decorator was either omitted or applied incorrectly above the method definition, or if the method name was misspelled.","error":"AttributeError: 'MyClass' object has no attribute 'my_property_name'"},{"fix":"Use `cached_property` directly as a decorator without parentheses (`@cached_property`), and only apply it to methods that act as properties (i.e., take only `self` as an argument).","cause":"This error typically indicates that `cached_property` was called as a function with parentheses (e.g., `@cached_property()`) without the method being passed, or that it was applied to a method that expects arguments other than `self`.","error":"TypeError: cached_property() takes 1 positional argument but 2 were given"}]}