A sample program that demonstrates the functools.lru_cache:
1: import timeit2: import itertools3: import functools4: import sys5:6: @functools.lru_cache(maxsize=32)7: def myTestCacheFucntion (pKey ):8: print ("The method has been called")9: return "Hello:" + pKey10:11: print ( myTestCacheFucntion ("Zvika"))12:13: print (myTestCacheFucntion ("Shahf"))14:15: print (myTestCacheFucntion ("Zvika"))16:17: print (myTestCacheFucntion ("Shahf"))18:19: sys.exit()
And the result
The method has been called
Hello:Zvika
The method has been called
Hello:Shahf
Hello:Zvika
Hello:Shahf
Traceback (most recent call last):
File "C:\blogs\test1\testpy.py", line 19, in <module>
sys.exit()
SystemExit
אין תגובות:
הוסף רשומת תגובה