pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.64k stars 258 forks source link

Ability to clear cache of memoized functions #228

Open jiffyclub opened 9 years ago

jiffyclub commented 9 years ago

Function's decorated with functools' lru_cache have a cache_clear() function attached to them so that the cache can be manually invalidated. It'd be useful to me if toolz's memoize function did the same thing.

eriknw commented 9 years ago

Yeah, it should definitely be possible to clear a cache. I think it is sufficient to expose func, cache, and key as attributes of the memoized function.

Unlike lru_cache, memoize can accept a cache object from the user. Giving the user direct access to that is more flexible.

xrr commented 8 years ago

It would also be useful to do a "cache refresh", on a given call, ie.:

  1. clear from cache specifically the key associated to the given call
  2. do a "regular call" (obtain result from decorated function, save it into the cache & return it)