Skip to content

Commit

Permalink
complete task
Browse files Browse the repository at this point in the history
  • Loading branch information
Atom-gnomov committed Dec 21, 2024
1 parent d00f7d9 commit 00a165e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@


def cache(func: Callable) -> Callable:
cache_save = {}
cache_dict = {}

def wrapper(*args, **kwargs) -> any:
cache_key = (args, tuple(sorted(kwargs.items())))
if cache_key in cache_save:
if cache_key in cache_dict:
print("Getting from cache")
return cache_save[cache_key]
return cache_dict[cache_key]
else:
print("Calculating new result")
result = func(*args, **kwargs)
cache_save[cache_key] = result
cache_dict[cache_key] = result
return result
return wrapper

0 comments on commit 00a165e

Please sign in to comment.