Design Cache Q: How would you prioritize above operations to keep latency to a minimum for our system?
May I ask how to achieve
Hi Steven, Lets say our hashmap is implemented using hashing with chaining ( http://opendatastructures.org/ods-cpp/51HashingwithChaining.html ) . Lets say we get an update operation where we have to update Hash to a new value 100. We would look up the corresponding hash for 246 and then go to the row corresponding to that. Now, one way of update would be to lock the whole row, traverse the linked list to the node which corresponds to 246 and then update its value to 100. Another way to do it might be to not acquire a lock for the whole, but rather acquire a lock just for the corresponding node, and then update its value to 100. Out of the 2 ways, second way is more granular.
How you make the writes more granular depends heavily on the choice of data structures and the level of trade-offs we are willing to make.
Do we really need synchronization here? If thread t1 is trying to remove a value from cache and t2 is trying to read it at the same time - does it really matter for us what operation occurs first? Even if t2 reads the data that's it outdated already, is it such a big deal for cache? Isn't a better performance more important for us in case of cache then consistency?
What do we mean by higher level Read lock?
Highly unclear this section. The formatting is really nasty …
IMHO a read operation has not completed successfully until both operation 1 and 2 have completed successfully. So making operation 2 async will bring in higher inconsistency.