-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIFOPolicy.java
More file actions
34 lines (25 loc) · 780 Bytes
/
FIFOPolicy.java
File metadata and controls
34 lines (25 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Map;
//FIFO models on age
public class FIFOPolicy implements EvictionPolicy {
private Queue<String> queue; //stores keys in order they were added
public FIFOPolicy(){
this.queue = new ArrayDeque<>();
}
@Override
public void onInsert(String key){ //called when new entry is added to cache
queue.add(key);
}
@Override
public void onAccess(String key){ //called when something is read
//FIFO doesnt care about access...
}
@Override
public String chooseEvictionKey(
Map<String, CacheEntry> entries,
Metrics metrics
){ //called when cache is full
return queue.poll();
}
}