Skip to content

Commit

Permalink
solution to py-cache-decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Annolel committed Nov 18, 2024
1 parent 5891c38 commit c83c0e5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@


def cache(func: Callable) -> Callable:
# Write your code here
pass

tmp_cache = {}

def inner(*args) -> None:
if args in tmp_cache:
print("Getting from cache")
return tmp_cache[args]
else:
print("Calculating new result")
result = func(*args)
tmp_cache[args] = result
return result
return inner

0 comments on commit c83c0e5

Please sign in to comment.