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 ) { log . warn ( "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 ; } } }
Clears all entries out of cache where the entries are older than the maximum defined age .