Skip to content

Commit

Permalink
Improved Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatrovskyi committed Sep 29, 2023
1 parent c16ff11 commit 43d49ab
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ def cache(func: Callable) -> Callable:
cached = {}

def inner(*args, **kwargs) -> Any:
if args in cached:
print("Getting from cache")
else:

if args not in cached:
new_cache = func(*args)
cached[args] = new_cache
print("Calculating new result")
else:
print("Getting from cache")

return func(*args) if args not in cached.keys() else cached[args]
return cached[args]

return inner

0 comments on commit 43d49ab

Please sign in to comment.