DEV Community

Discussion on: Cache Me Outside: Speed Boosts in Python

Collapse
 
rpalo profile image
Ryan Palo • Edited

It's pretty much the same. There are a couple benefits though.

  1. You don't have to write your own memoization function. You get to use one that has already been error checked, optimized for efficiency, and merged into the standard library. It's got Guido's stamp of approval 👍🏻
  2. LRU cache comes with an additional maxsize parameter which can help with tuning for memory management (i.e. not growing your cache to infinity). Setting maxsize to 0 effectively gives you a basic memoization decorator.
  3. You don't have to write it, you don't have to write tests for it, you don't have to maintain it, you don't have to write docs for it. The easiest code to debug is the code that never gets written. There are probably benefits to writing your own too though. Just depends on what you want.