python: functools.lru_cache (beginner – intermediate) anthony explains #54

today I explain functools.lru_cache as well as a few ways that you might use it in your programs!

– decorators video:



All code / presentations are hosted on github:

Anthony’s github:

I won’t ask for subscriptions / likes / comments…

Similar Posts

10 thoughts on “python: functools.lru_cache (beginner – intermediate) anthony explains #54
  1. Thanks for the video. Can you maybe make a video on the variable types, e.g. in the video you write: def square(x: float) -> float. What's the usefulness of it other than you explicitly see what are the variable types, in this case input and output are floats.

  2. Can a logger be benefited by slamming lru_cache on every single* method of the Logger class?
    I did profiling on the logger class and turns out the number of function call were reduced but is it still safe to assume that this slamming most of the methods with lru_cache is okay? Implementation wise the output of the logger is correct so haven't had any issues with that as well, just curious if it is good implementation or am I missing something big here?

  3. You mentioned that the large cache is wasteful on that function that will only ever return one value, but is it? I assumed the cache is just like a dictionary or something so it wouldn't reserve space for up to maxsize, so if you only ever put one item in it, the size would be the same no matter what you set maxsize to.

  4. I am spamming you with lots of comments, apologies for this… do you think this can be used within AWS lambda functions? I have a specific use case to retrieve read only data which is only updated nightly, given the lambda container doesnt hang around all that long I am wondering if I could use this as a cache for json data instead of the additional overhead and complexity of adding elasticache in. I guess what would be even better were if the cache TTL could be controlled?

Leave a Reply

Your email address will not be published. Required fields are marked *