Sign in
Log inSign up
theroyakash

4 comments

Luiz Filipe da Silva
Luiz Filipe da Silva
Dec 26, 2020

Great one! I'll be using this decorator in future needs. Thanks for sharing!

4
·
·1 reply
theroyakash
theroyakash
Author
·Dec 26, 2020

Glad you liked it

2
·
Sébastien Portebois
Sébastien Portebois
Dec 26, 2020

Did you try timing it against the built-in cache functions Python provides?

eg docs.python.org/3/library/functools.html

It’s indeed a good way to introduce how to create custom decorators, but for this caching purpose, I’d believe the built-in implementation will be faster.

3
·
·1 reply
theroyakash
theroyakash
Author
·Dec 27, 2020

The built in caching function has a limited storage space and unused cached elements are evicted with LRU policy. As both uses a dictionary to store the data cache access time would be same O(1) constant

1
·