Skip to content

Commit

Permalink
sol
Browse files Browse the repository at this point in the history
  • Loading branch information
Familenko committed Sep 27, 2023
1 parent 5891c38 commit e03c628
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
from typing import Callable
from typing import Callable, Any
from functools import wraps


def cache(func: Callable) -> Callable:
# Write your code here
pass
cached = []
arg_cache = []

@wraps(func)
def wrapper(*args) -> Any:
nonlocal cached, arg_cache

if args not in arg_cache:
print("Calculating new result")
result = func(*args)
cached.append(result)
arg_cache.append(args)

return result

else:
print("Getting from cache")

return cached[arg_cache.index(args)]

return wrapper

0 comments on commit e03c628

Please sign in to comment.