mirror of
https://github.com/Andreabont/PyExperiments.git
synced 2024-09-19 14:43:05 +00:00
8 lines
316 B
Python
8 lines
316 B
Python
|
# Alla prima chiamata si salva il risultato e ritorna sempre quello. Adatta se la funzione è costante
|
||
|
def constantCache(function):
|
||
|
def wrapper(*args, **kwargs):
|
||
|
if 'result' not in wrapper.__dict__:
|
||
|
wrapper.result = function(*args, **kwargs)
|
||
|
return wrapper.result
|
||
|
return wrapper
|