What's the advantage of deleting a record over updating a record in Memcached?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

By deleting the item, you aren't forcing a potentially unnecessary load. Say for example that the record gets updated several times in a row before being read from the cache. You will have updated the cache several times for no reason; If you removed the item from the cache after the first update, all of the later updates would execute (not requiring the cache to be populated each time), and then only when the item is actually needed is it loaded from the database and put into the cache.

So you are assuming that, you use what you read from DB to update the cache. Consider the situation that I only need to update one key-value pair: if the db update is successful(in Java, this means executeUpdate() returns 1), then I don't need to query DB again, instead I can just directly update the cache with the new value at hand. In this case, the overhead of updating the cache is minimal, right?

– No4Clipper May 5 at 3:01 Any data you are writing more often than you are reading is likely not a good candidate for caching. At the very least you should collect some data to confirm your are getting some value out of caching something like this. – Jake T.

May 5 at 3:56 @No4Clipper - Even taking out the cost of the DB, you are still updating a cache entry that wasn't required; Letting the next request for the item bring it into the cache is properly controlling the items lifetime in the cache. Updating the item in the cache is artificially extending its lifetime in the cache. – Chris Shaffer May 5 at 13:01 @Jake - There are circumstances where several separate updates might happen to an item but the item is still a good candidate for caching.

For example, many businesses require nightly processes to run to update various attributes (eg, pricing and stock quantities for a store). This may best be accomplished by several separate processes rather than one process, in which case the items will have multiple updates during the night. During standard business hours however, the items aren't updated - and are good to cache.

– Chris Shaffer May 5 at 13:08 Yes that's certainly a good point. If your application exhibits that type of behavior deleting would be the better choice. – Jake T.

May 5 at 16:32.

The major advantage of delete over update is that it is simpler. To update you may need to do the following: Handle failures of the cas command (probably by falling back to delete) Keep a copy of the original cas unique value for use in the cas command Be able to create a complete new value to put in the cache These requirements restrict the way you can structure your code in significant ways. If your consistency requirements are especially weak you could just slam values into the cache with the set command which would similarly simple to implement.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions