/** * Removes expired elements. * * <p>Note that the DiskStore cannot efficiently expire based on TTI. It does it on TTL. However * any gets out of the DiskStore are check for both before return. * * @noinspection SynchronizeOnNonFinalField */ public void expireElements() { final long now = System.currentTimeMillis(); // Clean up the spool synchronized (spoolLock) { for (Iterator iterator = spool.values().iterator(); iterator.hasNext(); ) { final Element element = (Element) iterator.next(); if (element.isExpired()) { // An expired element if (LOG.isDebugEnabled()) { LOG.debug(name + "Cache: Removing expired spool element " + element.getObjectKey()); } iterator.remove(); notifyExpiryListeners(element); } } } Element element = null; RegisteredEventListeners listeners = cache.getCacheEventNotificationService(); synchronized (diskElements) { // Clean up disk elements for (Iterator iterator = diskElements.entrySet().iterator(); iterator.hasNext(); ) { final Map.Entry entry = (Map.Entry) iterator.next(); final DiskElement diskElement = (DiskElement) entry.getValue(); if (now >= diskElement.expiryTime) { // An expired element if (LOG.isDebugEnabled()) { LOG.debug( name + "Cache: Removing expired spool element " + entry.getKey() + " from Disk Store"); } iterator.remove(); // only load the element from the file if there is a listener interested in hearing about // its expiration if (listeners.hasCacheEventListeners()) { try { element = loadElementFromDiskElement(diskElement); notifyExpiryListeners(element); } catch (Exception exception) { LOG.error( name + "Cache: Could not remove disk store entry for " + entry.getKey() + ". Error was " + exception.getMessage(), exception); } } freeBlock(diskElement); } } } }
private void notifyEvictionListeners(DiskElement diskElement) { RegisteredEventListeners listeners = cache.getCacheEventNotificationService(); // only load the element from the file if there is a listener interested in hearing about its // expiration if (listeners.hasCacheEventListeners()) { Element element = null; try { element = loadElementFromDiskElement(diskElement); cache.getCacheEventNotificationService().notifyElementEvicted(element, false); } catch (Exception exception) { LOG.error( name + "Cache: Could not notify disk store eviction of " + element.getObjectKey() + ". Error was " + exception.getMessage(), exception); } } }