brmscheiner/memorize.py

Accept function to create hashable keys from args

brmscheiner opened this issue · 4 comments

Based on discussion with @JoranDox in #3

Allow users to provide a function that maps arguments to some sort of hashable key. This will enable people to use the Memorize decorator with functions that accept non-hashable arguments. Target API:

def getHash(arg1, arg2):
    return str([arg1, arg2])

@Memorize(getHash)
def myFunction(arg1, arg2):
    ....

One caveat: I think we will need to save a hash of the function to the cache as well, so that when myFunction is called again we can verify that the getHash function has not changed.

@cjbassi do you have an opinion about this?

I think the concept looks good. So check getHash when Memorize is initialized? And recreate the cache file if it has changed?

yes, that's the idea