tryEvictHead checks if the oldest item (head of list) can be evicted and will delete it if so. Returns true if the head was evicted. Must be called holding lock.
()
| 69 | // |
| 70 | // Must be called holding lock. |
| 71 | func (s *store) tryEvictHead() bool { |
| 72 | head := s.l.Front() |
| 73 | if head == nil { |
| 74 | // list is empty |
| 75 | return false |
| 76 | } |
| 77 | |
| 78 | headEdge := head.Value.(*Edge) |
| 79 | if !headEdge.isExpired() { |
| 80 | return false |
| 81 | } |
| 82 | |
| 83 | s.onExpire(headEdge) |
| 84 | s.deleteEdge(head) |
| 85 | |
| 86 | return true |
| 87 | } |
| 88 | |
| 89 | // deleteEdge removes an edge from the map/list and returns it to the pool. |
| 90 | // Must be called holding lock. |