简体   繁体   中英

python @memoize vs functools.lru_cache

I'm not sure what the advantages and disadvantages of these 2 are. Provided @lru_cache from functools is a standard library tool and seems to have more control over @memoize , why does @memoize even exist?

Edit: I am referring to memoize from here -> https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize

functools.lru_cache was added in python 3.2. For those using python 2, and for libraries written to work with it (eg all major libs) it cannot be used.

The workaround is to use the @memoize recipe from the decorator library.

If you only use python 3, there is basically no reason not to use lru_cache .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM