Feature Request: Panel Cache on args subset

Is it possible to define a subset of args to cache on?

I find that panel caching fails when argument types to methods include non-hashable types like methods or functions. It would be nice to be able to define a subset of function arguments to hash on such that functional arguments can be ignored.

For example

import panel as pn

@pn.cache('id', to_disk=True)
def get_data(id: int, load_data: Callable):
    return load_data(id)

data = get_data(357, load_data=data_connector)

What if you wrap @pn.cache around load_data, e.g. data_connector instead?

import panel as pn

def get_data(id: int, load_data: Callable):
    return load_data(id)

data = get_data(357, load_data=pn.cache(data_connector, to_disk=True))

Or perhaps manually cache:

import panel as pn

def get_data(id: int, load_data: Callable):
    if pn.state.cache.get(id):
        return pn.state.cache[id]
    return load_data(id)

data = get_data(357, load_data=data_connector)
1 Like