Actually you can get the cache data from the python version, for that you need to force the use of the python version of functools
def get_cache(f):
freevars = f.__code__.co_freevars
index = freevars.index('cache')
return f.__closure__[index].cell_contents
import importlib.abc
class ForcePythonLruCache(importlib.abc.MetaPathFinder):
def find_spec(self, fullname, path, target=None):
if fullname == '_functools':
raise ImportError('_functools not available')
import sys
del sys.modules['functools']
del sys.modules['_functools']
import functools
@functools.lru_cache
def test(x):
return x
test(1)
test(2)
test('a')
test('foo')
print(list(get_cache(test).keys()))
--
Sebastian Kreft