How would a LRU cache work on a single machine which is multi threaded?


#1

Design Cache Q: How would a LRU cache work on a single machine which is multi threaded ?


#2

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 ?


#3

Every row has a link list of entries. So lock on the linkedlist is lock on the head of the linked list.


#4

Presumably you'd have a separate lock for each cell in your array (so an array of locks).


#5

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.


#6

looks like a concurrent hashmap can be used here ...http://stackoverflow.com/questions/7700303/concurrency-at-the-data-row-level


#7

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?


#8

I didn’t understand this section. Why just have lock on hash map, what about DLL ?