Python: How use use lru_cache with staticmethod

2020.04.27 | 39 words |

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 - I built this! If you want more content like this subscribe to my email list, connect with me around the web, or take a look at some of my other projects.

More Projects

comments powered by Disqus