Skip to content

Commit

Permalink
Cache decorator function for reviewing
Browse files Browse the repository at this point in the history
  • Loading branch information
tkudinov committed Nov 21, 2024
1 parent 5891c38 commit 12ab764
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
from typing import Callable
from functools import wraps


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

@wraps(func)
def wrapper(*args) -> dict:
if isinstance(args, (str, int, float, tuple, bool)):
if args in cache_storage:
print("Getting from cache")
return cache_storage[args]
else:
print("Calculating new result")
result = func(*args)
cache_storage[args] = result
return result
else:
print("Not immutable data")
return wrapper

0 comments on commit 12ab764

Please sign in to comment.