Skip to content

Commit

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


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

@wraps(func)
def wrapper(*args: Any) -> Callable:
cache_key = (func.__name__, args)
if cache_key in cache_storage:
print("Getting from cache")
return cache_storage[cache_key]
else:
print("Calculating new result")
# Calculate and store the result in the cache
result = func(*args)
cache_storage[cache_key] = result
return result

return wrapper

0 comments on commit 1131945

Please sign in to comment.