Skip to content

Commit

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


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

@functools.wraps(func)
def wrapper_cache(*args) -> Any:
key = args
if key not in memory:
memory[key] = func(*args)
print("Calculating new result")
return memory[key]
else:
print("Getting from cache")
return memory[key]

return wrapper_cache

0 comments on commit c7af899

Please sign in to comment.