Search code examples
pythoncachingring

Python Ring cache library: ignore None value


How should I tell ring.dict to ignore None value, in other words don't cache if the result of the function is None.


Solution

  • The answer on my question is: there is no way to do it. You would need to create your own decorator and it would not be easy.

    The simplest way and correct from code perspective is to throw exception in the function that returns result. So if you have like me a function that sometimes can return None that you don't want to cache, change your design and make this function to raise an exception in this case.