{
Object[] keys = cache.getKeyArray();
int size = keys.length;
Serializable key;
ICacheElement cacheElement;
IElementAttributes attributes;
for ( int i = 0; i < size; i++ )
{
key = ( Serializable ) keys[ i ];
cacheElement = cache.getQuiet( key );
if ( cacheElement == null )
{
continue;
}
attributes = cacheElement.getElementAttributes();
boolean remove = false;
long now = System.currentTimeMillis();
// Useful, but overkill even for DEBUG since it is written for
// every element in memory
//
// if ( log.isDebugEnabled() )
// {
// log.debug( "IsEternal: " + attributes.getIsEternal() );
// log.debug( "MaxLifeSeconds: "
// + attributes.getMaxLifeSeconds() );
// log.debug( "CreateTime:" + attributes.getCreateTime() );
// }
// If the element is not eternal, check if it should be
// removed and remove it if so.
if ( !cacheElement.getElementAttributes().getIsEternal() )
{
remove = checkForRemoval( cacheElement, now );
if ( remove )
{
cache.remove( cacheElement.getKey() );
}
}
// If the item is not removed, check is it has been idle
// long enough to be spooled.
if ( !remove && ( maxMemoryIdleTime != -1 ) )
{
final long lastAccessTime = attributes.getLastAccessTime();
if ( lastAccessTime + maxMemoryIdleTime < now )
{
if ( log.isDebugEnabled() )
{
log.debug( "Exceeded memory idle time: "
+ cacheElement.getKey() );
}
// FIXME: Shouldn't we ensure that the element is
// spooled before removing it from memory?
cache.remove( cacheElement.getKey() );
cache.waterfal( cacheElement );
}
}