The problem is that a caching system uses the LRU algorithm, assuming that the cache capacity is 4, and the initial is empty, then in order to access the following data items,
1,5,1,3,5,2,4,1,2
The number of cached direct hits is (), and the data items that are about to be eliminated in the last cache are ().
Let's explain the concept.
LRU (least recently Used) algorithm: It is the most recent use of time from the current time farthest from the data deleted. Concrete implementation Please see this blog "How to implement LRU caching algorithm with Linkedhashmap"
Here's how to solve the problem, we list the state of the cache when accessing data items each time
1
1,5
5,1 hit
5,1,3
1,3,5 hit
1,3,5,2
3,5,2,4 exceeds cache capacity limit, delete 1
5,2,4,1 exceeds cache capacity limit, delete 3
5,4,1,2 hit
So the answer comes out, the direct hit Count is 3, the final cache is ready to be eliminated in the data item is 5