I have an application that receives messages from devices every few minutes. I also have clients that request the last 10 messages for a particular device.
I am suffering with some database saturation and I wish to cache this list by device. The basic premise is that when a message is received from the device then the processor that receives the messages will invalidate the cache for that device.
My question is whether I should just invalidate the cache and then have it rebuilt when the next client connects, or should I have the device processor rebuild the cache pre-emptively. The device processor can retrieve the current cache pop the last entry off, add the new entry and cache the new result.
I appreciate that this may be an it depends, answer but I would appreciate hearing peoples own experiences in this area.