Design Cache Q: How would a LRU cache work on a single machine which is multi threaded ?
How to take lock at row level? Like in Java, a 'Lock' object per row of table ? I know that InnoDB takes row level lock but how to implement one of our own ?
Every row has a link list of entries. So lock on the linkedlist is lock on the head of the linked list.
Presumably you'd have a separate lock for each cell in your array (so an array of locks).
That'd be one way. Since each cell in array will be a linkedlist of nodes. You can use the head of linkedlist in each cell to synchronize over.
looks like a concurrent hashmap can be used here ...http://stackoverflow.com/questions/7700303/concurrency-at-the-data-row-level
Why we don't need to lock the doubly linkedlist. If read and write are asynchronously on moving the node to the head of list, what we remove from head of doubly linkedlist can be wrong. Does that matter?
I didn’t understand this section. Why just have lock on hash map, what about DLL ?