Skip to content

Commit

Permalink
implement py-cache-decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
muriakula committed Nov 12, 2024
1 parent 5891c38 commit 6c6eaae
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@


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

def wrapper(*args, **kwargs) -> Callable:
key = (args, tuple(kwargs.items()))
if key in cache_args:
print("Getting from cache")
else:
print("Calculating new result")
cache_args[key] = func(*args, **kwargs)
return cache_args[key]
return wrapper

0 comments on commit 6c6eaae

Please sign in to comment.