cached_method
The equivalent of cached_property for methods
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 on this page — 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
cached-method on PyPI
pip
pip install cached-methoduv
uv add cached-methodpoetry
poetry add cached-methodInstalling 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 the current Python release (>= 3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,748 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 77,437/month — #14,524 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cached_method-0.1.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
propcacheProvides fast cached-property decorators for…
permissive · top 100 on PyPI
methodtoolsProvides LRU caching for methods, classmethods,…
permissive · top 5,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
backports.cached-propertyProvides the cached_property decorator for…
permissive · top 15,000 on PyPI
django-memoizeCaches function and method results in Django…
permissive · top 15,000 on PyPI
cachierCachier is a decorator that adds persistent,…
permissive · top 15,000 on PyPI
django-cache-memoizeA decorator that caches function results using…
copyleft · top 15,000 on PyPI
cache-to-diskA decorator that caches function results to…
permissive · top 15,000 on PyPI
kleptoklepto provides multiple caching algorithms…
permissive · top 15,000 on PyPI
weakrefmethodProvides a WeakMethod class for storing bound…
permissive · top 15,000 on PyPI