Skip to content

Commit

Permalink
Cache decorator solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyutillis committed Sep 28, 2023
1 parent 5891c38 commit d1c4c10
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@


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

def wrapper(*args):
if args in stored_runs:
print("Getting from cache")
return stored_runs[args]
print("Calculating new result")
stored_runs.update({args: func(*args)})
return stored_runs[args]
return wrapper

0 comments on commit d1c4c10

Please sign in to comment.