-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59d4bd5
commit b27901d
Showing
1 changed file
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
from typing import Callable, Any | ||
|
||
|
||
def cache(func: Callable) -> Callable: | ||
def cache(numero: int) -> Any: | ||
def wrapper(*args, **kwargs) -> Any: | ||
result = func(*args, **kwargs) | ||
return result | ||
def inner(func: Callable) -> Any: | ||
results = [] | ||
for _ in range(numero): | ||
results.append(func(*args, **kwargs)) | ||
for result in results: | ||
if results.count(result) > 1: | ||
print(f"Getting from cache {result}") | ||
else: | ||
print(f"Calculating new result {result}") | ||
return inner | ||
return wrapper | ||
|