Python: How use use lru_cache with staticmethod

Published: 2020-04-27 21:15:13 -0400 -0400

Reading time: 1 mins (39 words)

Tags: python lru-cache staticmethod

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():
    ...

About the Ham

Hi I'm Hamilton and I wrote / built this! I like doing lots of things, but mostly I like to build (and then share those buildings). Some things I'm currently building: art, software, and prose. To stay up-to-date with my latest buildings, subscribe to my email list or follow one of my many other accounts. #buildit #shipit #justhamit

comments powered by Disqus