-
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
5891c38
commit c4a01f7
Showing
1 changed file
with
14 additions
and
3 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,6 +1,17 @@ | ||
from typing import Callable | ||
from typing import Callable, Any | ||
|
||
|
||
def cache(func: Callable) -> Callable: | ||
# Write your code here | ||
pass | ||
storage = {} | ||
|
||
def wrapper(*args: Any) -> Any: | ||
storage_keys = storage.keys() | ||
if args not in storage_keys: | ||
print("Calculating new result") | ||
result = func(*args) | ||
storage[args] = result | ||
else: | ||
print("Getting from cache") | ||
result = storage[args] | ||
return result | ||
return wrapper |