Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Czernich committed Dec 3, 2024
1 parent 5891c38 commit 595b4a4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,20 @@


def cache(func: Callable) -> Callable:
# Write your code here
pass
results = {}

def inner(*args) -> None:
if func.__name__ in results and args in results[func.__name__]:
print("Getting from cache")
return results[func.__name__][args]

print("Calculating new result")
result = func(*args)
if func.__name__ not in results:
results[func.__name__] = {}

results[func.__name__][args] = result

return result

return inner

0 comments on commit 595b4a4

Please sign in to comment.