# Adding a method caching decorator to functools

**URL:** <https://discuss.python.org/t/adding-a-method-caching-decorator-to-functools/107164>\
**Category:** Ideas\
**Created:** [May 3, 2026, 4:51am UTC](https://discuss.python.org/t/adding-a-method-caching-decorator-to-functools/107164 "2026-05-03T04:51:24Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![methane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/methane/32/43_2.png) [@methane](https://discuss.python.org/u/methane)\
**Post date:** [May 4, 2026, 3:56pm UTC](https://discuss.python.org/t/adding-a-method-caching-decorator-to-functools/107164/21 "2026-05-04T15:56:42Z")

</div>

In my company’s project, we needed isolated caches for each instance. After researching existing implementations, we adopted [cached\_method](https://pypi.org/project/cached_method/).

Implementation: [cached\_method/cached\_method.py at main · martenlienen/cached\_method · GitHub](https://github.com/martenlienen/cached_method/blob/main/cached_method.py)

The `cached_method` behaves as follows:

1. The decorated method generates a cache instance upon the first access, similar to a cached property.

2. The cache instance is created by wrapping the bound method with `lru_cache`, meaning that `self` is not included in the cache key.

3. When wrapping the bound method with `lru_cache`, weak references are used to prevent circular references. However, even without using weak references, memory leaks do not occur.

Our project is a web API server that utilizes multithreading. When an instance occupied by a thread uses `cached_method`, its cache is completely isolated from other threads too. This design is simple and robust, and since the cache is released immediately when the instance is released, there is little concern about worsening memory pressure.

---

_[View the full topic](https://discuss.python.org/t/adding-a-method-caching-decorator-to-functools/107164)._
