This is a skeleton of the function I want to enhance with a cache, because doing RPC (remote procedure call) involves a TCP connection to other host.
def rpc(rpc_server, rpc_func, arg):
return rpc_server.do_rpc(rpc_func, arg)
However, the most convenient way of simply decorating it with:
@functools.lru_cache()
does not work well, beacuse rpc_server
objects come and go and this parameter should be ignored by the cache.
I can write a simple memoizing code myself. No problem with that. Actually, I see no other solution.
I am unable to rewrite this function in such way that @lru_cache()
decorator can be applied and rpc_server
will be passed as an argument (i.e. I don't want to make rpc_server
a global variable). Is it possible?