lonelyenvoy / python-memoization

A powerful caching library for Python, with TTL support and multiple algorithm options.
MIT License
230 stars 15 forks source link

remove particular element from cache? #19

Closed rmrmg closed 3 years ago

rmrmg commented 3 years ago

Hello I have function which can return results or timeout, simplified example is below:

@cache()
def longjob(args):
   try:
      data =  getdata(args)
      return data
  except timeout:
      return 'data not available try again later'

When function cannot return data there is no reason to cache result. Is there any way to remove single entry from cache? I am aware of clear_cache() but this remove all cached values.

lonelyenvoy commented 3 years ago

Feature implemented in v0.4.0. Now available at PyPI or GitHub Releases.

Please upgrade by: pip install -U memoization

Use this API: cache_remove_if(predicate)