How do I rename a Diskcache memoization cache?

27 Views Asked by At

diskcache.Cache objects provide a memoize function, which can be used like this:

cache = Cache(...)

@cache.memoize()
def long_computation(*args):
    ...

One can provide a name argument to cache.memoize to uniquely identify the callable being decorated. If one omits this argument (as in the example above), it's inferred from the full name of the callable.

However, the full name of the callable depends on how (and whether) you're importing it - which is undesirable to me, as it means different scripts "see" the function as having different names, and therefore do not share the computation cache and wind up repeating work between them.

The fix is simple: add an explicit name to the decorator call above. However, I've already done a fair amount of computation under the inferred name, and don't want to have to redo it. So I'd like some way to rename the existing cache to the new (explicit) name, so future calls can still use it.

0

There are 0 best solutions below