Skip to content

Commit

Permalink
new_Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Damodar-kumar committed Sep 21, 2023
1 parent f847c12 commit 2a2126f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
from typing import Callable

results_list = []


def cache(func: Callable) -> Callable:
results_list = []

def inner(*args) -> Callable:
global results_list
nonlocal results_list
for result in results_list:
if (result["arguments"] == [*args]
and result["id_func"] == id(func)):
if result["arguments"] == [*args]:
print("Getting from cache")
return result["result_func"]
results_list += [
{
"arguments": [*args],
"result_func": func(*args),
"id_func": id(func)
"result_func": func(*args)
}
]
print("Calculating new result")
return results_list[-1].get("result_func")

return inner

0 comments on commit 2a2126f

Please sign in to comment.