Essay record

Python: How use use lru_cache with staticmethod

Record
Essay / / 1 min read / 43 words
On this page2 sections / +

DISCLOSURE: Some links may be affiliate links. Details

problem

I'm trying to use lru_cache with a staticmethod function.

solution

To use lru_cache with staticmethod, you just have to make sure that lru_cache is directly on top of the callable function.

Example:

@staticmethod
@lru_cache(maxsize=8)
async def a_static_method():
    ...

Built with CloudSeed Rust