Does cache work for factory function?

Hi,
I am checking whether it is possible to make my jit function customizable by passing in a user-defined function. I found the useful documentation here. It suggests to use the factory function. I wonder how does cache work on the returned function?
For example, when calling the factory twice, does the returned function share the cache? (Does f1 and f2 share the cache or they must be recompiled every time?)

def make_f(g):
    @jit(nopython=True, cache=True)
    def f(x):
        return g(x) + g(-x)
    return f

@njit
def g(x):
    return x + 1
f1 = make_f(g)
print(f1(1))
f2 = make_f(g)
print(f2(1))

Hi @wuyuanyi135

This isn’t implemented yet, there’s a feature request here Caching: functions captured in closure · Issue #6264 · numba/numba · GitHub and PR to in part fix it here Prevent cache busting by the UUID of Dispatcher by sk1p · Pull Request #6284 · numba/numba · GitHub. I suggest subscribing to those tickets if you are interested in updates.

Hope this helps?

1 Like

Thank you for the informative response. I will keep track these changes!