-
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.
Try to fix Valentine's remarks ver.2
- Loading branch information
1 parent
8866462
commit f7828d6
Showing
1 changed file
with
4 additions
and
5 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,17 +1,16 @@ | ||
from typing import Callable | ||
from typing import Callable, Any | ||
|
||
|
||
def cache(func: Callable) -> Callable: | ||
cached_data = {} | ||
|
||
def wrapper(*args) -> Callable: | ||
|
||
def wrapper(*args) -> Any: | ||
if args in cached_data: | ||
print("Getting from cache") | ||
return cached_data[args] | ||
|
||
else: | ||
print("Calculating new result") | ||
cached_data[args] = func(*args) | ||
return cached_data[args] | ||
return cached_data[args] | ||
|
||
return wrapper |