- 0of 0 votes
Create a function Demo that takes input a function f and a parameter k, and returns a function that behaves the same as f except it caches the last k distinct accessed results of f.
Demo_f = Demo(f,2)
demo_f(arg1) - computed and cached
demo_f(arg1)- returned from cache
demo_f(arg2) - computed and cached
demo_f(arg3) - computed and cached, f(agr1) is evicted
I think its related to python decorators. Some one can give a hint how can I get started with this