I am using dogpile to have cache in my python program.
During the init of my program, I clean the cache SimpleCache.set_fault_injector(NO_VALUE)
@staticmethod
def set_fault_injector(injector):
SimpleCache.save("fault_injector", injector)
Then I retrieve the object with:
@staticmethod
def get_fault_injector():
return SimpleCache.get("fault_injector")
injector = get_fault_injector()
Here in my test, I am checking if the injector
variable is set to NO_VALUE
, but the comparison is returning False
(it should be TRUE
). How do I check if injector
is set to NO_VALUE
? The way that I clear the cache is correct?
In [3]: injector
Out[3]: <dogpile.cache.api.NoValue at 0x7fdde0dfd750>
In [4]: NO_VALUE
Out[4]: <dogpile.cache.api.NoValue at 0x7fdde16dbed0>
In [5]: injector == NO_VALUE
Out[5]: False
In [6]: type(injector)
Out[6]: dogpile.cache.api.NoValue
In [7]: type(NO_VALUE)
Out[7]: dogpile.cache.api.NoValue
In [8]: injector is NO_VALUE
Out[8]: False
[9]: type(injector) == type(NO_VALUE)
Out[9]: True
I don't have experience in dogpile, however, from what I understand from the docs, when a value is missing then dogpile normally returns a specific instance of
dogpile.cache.api.NoValue
, which isNO_CACHE
.The issue here is probably linked to you explicitly setting a cache key to
NO_CACHE
, which somehow ends up leaving you with 2 different instances of theNoValue
class.It appears to me that
NO_CACHE
is not really meant to be used for unsetting a key, I believe your issue would be resolved if you actually used.delete("fault_injector")
or whatever removal method your cache wrapper has available.