--- id: cached-method version: "0.1.0" license: unclear license_treatment: permissive maintenance: abandoned --- # cached_method — The equivalent of cached_property for methods License: permissive · Maintenance: abandoned · Downloads: 77.4K/mo ## What it is and what it does cached_method is a decorator that caches method results on a per-instance basis, similar to functools.cached_property but for methods with arguments. Unlike functools.lru_cache applied directly to methods, it does not require the containing class to be hashable, and it does not maintain a global cache that extends object lifetimes. This is particularly useful for classes managing scarce resources like GPU memory, where you want objects and their caches to be garbage-collected together. The decorator closely mirrors functools.cached_property's implementation but omits internal locking, accepting the possibility of redundant method calls in multi-threaded contexts when equivalent arguments are used simultaneously. It also supports caching expensive operations like __hash__ without requiring the object itself to be hashable for cache lookups. Use it for: - Cache expensive GPU operations in tensor-based classes where immediate garbage collection matters. - Memoize method results for non-hashable objects without polluting a global cache. - Cache __hash__ computations for objects that perform costly transfers between devices. - Reduce redundant computation in methods called repeatedly with the same arguments within an instance. - Manage memory-intensive resources that should be freed when their owning object is deleted. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a method-level caching decorator that stores results per instance, avoiding the need for hashable classes and preventing global cache buildup. Yes, if you need per-instance method caching for non-hashable classes or resource-intensive objects. The code is simple and stable, but be aware the package is unmaintained since 2021-10-31—verify compatibility with your Python version before relying on it in production. For small hashable objects where global caching is acceptable, the standard functools approach may be preferable. ## Install pip install cached-method uv add cached-method poetry add cached-method ## Installing cached_method Before you install: Low install friction with no runtime dependencies. However, the package is abandoned—last release was 2021-10-31 with no updates since, though the repository remains public and the code is stable. License in practice: Licensed under MIT (permissive), so you may use, modify, and distribute freely with minimal restrictions. Quickstart: from cached_method import cached_method class Example: @cached_method(maxsize=2) def expensive_method(self, arg): return arg * 2 obj = Example() result = obj.expensive_method(arg) Requires Python >= 3.6. Verify before relying: - Whether the package works correctly with modern Python versions despite being unmaintained since 2021. - Performance characteristics compared to functools.lru_cache in typical use cases. - Thread-safety guarantees when methods are called concurrently with identical arguments. ## Package facts - License: not declared (permissive) - Python support: supports_current - Install friction: low - Maintenance: abandoned - Downloads: 77.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags method result caching, per-instance cache decorator, cached_property for methods, instance-level memoization, avoid lru_cache on methods, caching, memoization, resource-management [View on SkillFed](https://skillfed.io/packages/cached-method) · [View on PyPI](https://pypi.org/project/cached-method/)