Skip to content

Commit

Permalink
solution'
Browse files Browse the repository at this point in the history
'
  • Loading branch information
Piotr Zegarek committed Oct 19, 2024
1 parent 5891c38 commit ad704e1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,19 @@


def cache(func: Callable) -> Callable:
# Write your code here
pass
"""Caching decorator."""
cache_store = {} # Dictionary to store cached results

def wrapper(*args) -> Callable:
# Check if the result for given arguments is already cached
if (func, args) in cache_store:
print("Getting from cache")
return cache_store[(func, args)]
else:
# If not cached, calculate the result and store it in the cache
print("Calculating new result")
result = func(*args)
cache_store[(func, args)] = result
return result

return wrapper

0 comments on commit ad704e1

Please sign in to comment.