Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
JurassicGen committed Nov 18, 2024
1 parent 5891c38 commit 3ea2f41
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from typing import Callable
from typing import Callable, Any, Tuple, Dict


def cache(func: Callable) -> Callable:
# Write your code here
pass
cache_storage: Dict[Tuple, Any] = {}

def inner(*args, **kwargs) -> Callable:
key = (args, frozenset(kwargs.items()))
if key in cache_storage:
print("Getting from cache")
return cache_storage[key]
else:
print("Calculating new result")
result = func(*args, **kwargs)
cache_storage[key] = result
return result

return inner

0 comments on commit 3ea2f41

Please sign in to comment.