/** Erases all elements in the list and re-initializes it. */ public void clear() { // Remove all references in the list. LinkedListNode node = getLast(); while (node != null) { node.remove(); node = getLast(); } // Re-initialize. head.next = head.previous = head; }
/** Clears all entries out of cache where the entries are older than the maximum defined age. */ protected synchronized void deleteExpiredEntries() { // Check if expiration is turned on. if (maxLifetime <= 0) { return; } // Remove all old entries. To do this, we remove objects from the end // of the linked list until they are no longer too old. We get to avoid // any hash lookups or looking at any more objects than is strictly // neccessary. LinkedListNode node = ageList.getLast(); // If there are no entries in the age list, return. if (node == null) { return; } // Determine the expireTime, which is the moment in time that elements // should expire from cache. Then, we can do an easy check to see // if the expire time is greater than the expire time. long expireTime = System.currentTimeMillis() - maxLifetime; while (expireTime > node.timestamp) { if (remove(node.object, true) == null) { LOGGER.warning( "Error attempting to remove(" + node.object.toString() + ") - cacheObject not found in cache!"); // remove from the ageList node.remove(); } // Get the next node. node = ageList.getLast(); // If there are no more entries in the age list, return. if (node == null) { return; } } }