Skip to content

Commit

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


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

@wraps(func)
def wrapper(*args, **kwargs):
if args in cache_dict:
print("Getting from cache")
return cache_dict[args]
else:
print("Calculating new result")
result = func(*args, **kwargs)
cache_dict[args] = result
return result
return wrapper

0 comments on commit dc85bd4

Please sign in to comment.