Had an issue where something could not be cached that effected the load on our system.
Because of a bug, my code was calling a service with incorrect parameters and that service of course returned a 404, null, empty. Basically, nothing was found to satisfy the request. The fact that nothing was found was returned to a procedure that was caching the response. My caching system does not allow us to cache the value null so we basically could not cache the response or the fact that there was no response and therefor we had to make a live call every time this scenario happened. Because of the bug it happened a lot.
I have of course fixed the bug, but my question is whether or not there is and/or should be a way to cache the fact that some resource could not be found. If we could have had such a safety net in place the bug would not have been as severe.
Should there be a way to cache the fact that something is not found or not? Why or why not?
I am using memcache servers with a spymemcached client and my code is written in Java, though my question should be agnostic to that fact. Perhaps other implementations could provide a cacheKey exists method or something like that. I have researched this and haven’t found anything in the Java world that I think is adequate for my situation. Even if there were I might not be able to switch to it because of company standards.
When you need to know whether or not a value exists, and null is a valid value, I would typically use a “holder” or “singleton” class. For example:
So now instead of:
You can use: