Should I cache data ahead of schedule

I have an application that receives messages from devices every few minutes. I also have clients that request the last 10 messages for a specific device.

I am suffering from some database saturation and I want to cache this list using a device. The basic premise is that when a message is received from a device, the processor that receives the messages will strip the cache for that device.

My question is whether I should just invalidate the cache and then rebuild it when the next client is connecting, or should I have the device processor rebuild the cache to proactive. The device processor can retrieve the current cache, output the last entry, add a new entry, and cache a new result.

I appreciate that this may depend on this, answer, but I would appreciate it if people had experience in this area.

+4
source share
3 answers

I think you are describing the pre-fetch mechanism just to help you put a name in it. :)

I donโ€™t have much experience in this particular area, but if you think you can get the data in advance and reliably predict that this is what the client wants, and you get a measurable and desirable performance improvement because of this, then go ahead and give him a whirlwind.

Just remember to keep all the caching hairiness in mind. How this is not valid when changing basic data, etc. Good luck

+1
source

I do not think that you can answer this question until you determine how many times the client on average retrieves messages for this device. If a given device is only requested for messages once in the blue moon, then this is great to clear the message cache for every client request. However, if a given device message queue is requested multiple times, the preferred option is preferential caching during device synchronization; provided that device synchronization is less frequent than the client requests.

Itโ€™s best to write a system that adaptively caches based on load. If the requested device message queue is queried frequently, it updates the cache when the device is synchronized. If the device message queue is rarely requested, you update the cache when a client requests it.

+1
source

I heard, but it really depends. On many, many variables.

If it were me, I would most likely invalidate the cache and let the next client rebuild it, because it seems a little simpler, but I donโ€™t understand how you could determine which method works better without trying both of them .

I hope you can come up with a way to realistic simulate the heavy load on the client so that you do not mess with a live server.

0
source

All Articles