skillfed

cached_method

The equivalent of cached_property for methods

cached-method v0.1.0 77.4K downloads/30d#14,524 on PyPI11
Permissive license Abandoned released

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-method

uv

uv add cached-method

poetry

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 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python

Tags

method result cachingper-instance cache decoratorcached_property for methodsinstance-level memoizationavoid lru_cache on methods
cachingmemoizationresource-management

More Software Development packages