Here is the scenario: a simple website which queries a memcached cache. That same cache is updated by a batch job every 10-15 minutes. With that pattern is there anything that could go wrong (e.g. cache miss)?
I am concerned by all the possible racing condition that could happen. For example, if the website does a GET operation on an object cached in memcached while that same object is overridden by the batch job, what will happen?
Is memcached atomic? Aside from any bugs you may come across, yes all commands are internally atomic.
What is Memcached? Memcached is an easy-to-use, high-performance, in-memory data store. It offers a mature, scalable, open-source solution for delivering sub-millisecond response times making it useful as a cache or session store.
Memcached is designed for simplicity while Redis offers a rich set of features that make it effective for a wide range of use cases. Understand your requirements and what each engine offers to decide which solution better meets your needs.
Because Memcached is multithreaded, you can easily scale up by giving it more computational resources, but you will lose part or all of the cached data (depending on whether you use consistent hashing). Redis, which is mostly single-threaded, can scale horizontally via clustering without loss of data.
My initial instinct was that you should be able to read/write from a memcached cache with no side effects (other than a possibility of stale data due to race conditions).
On memcached's FAQ:
Is memcached atomic? Aside from any bugs you may come across, yes all commands are internally atomic. Issuing multiple sets at the same time has no ill effect, aside from the last one in being the one that sticks.
Without knowing more about your specific situation, I would not be able to advise on whether or not a cache miss was possible, but I do make a generalization that the cache should be a first tier for seeking data and not the ONLY tier; I would still have a database or some other source behind the cache to handle all of your cache misses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With