public Cacheable pop() { Cacheable next = head.nextCacheable; if (next == head) { return(null); } next.unlinkCacheable(); return(next); }
public void push(Cacheable item) { if (item.previousCacheable != null) { item.unlinkCacheable(); } item.previousCacheable = head.previousCacheable; item.nextCacheable = head; item.previousCacheable.nextCacheable = item; item.nextCacheable.previousCacheable = item; }
public void clear() { while (true) { Cacheable oldest = retrievedItems.pop(); if (oldest == null) { available = size; return; } oldest.unlink(); oldest.unlinkCacheable(); } }
public void put(Cacheable item, long key) { if (available == 0) { Cacheable oldest = retrievedItems.pop(); oldest.unlink(); oldest.unlinkCacheable(); if (oldest == empty) { Cacheable secondOldest = retrievedItems.pop(); secondOldest.unlink(); secondOldest.unlinkCacheable(); } } else { available--; } hashmap.put(key, item); retrievedItems.push(item); return; }