in src/experimental/org/apache/commons/jcs/engine/memory/arc/ARCMemoryCache.java [206:340]
public ICacheElement<K, V> ARC( ICacheElement<K, V> ce, boolean isGet )
{
cnt++;
logStatsOccassionally( ce, isGet );
if ( !isGet )
{
putCnt++;
}
ElementDescriptor temp = (ElementDescriptor) map.get( ce.getKey() );
boolean isHit = true;
if ( temp != null )
{
if ( isGet )
{
hitCnt++;
}
// determine where the element lives.
switch ( temp.listNum )
{
case _T1_:
handleFoundInT1( temp );
break;
case _T2_:
handleFoundInT2( temp );
break;
case _B1_:
temp = handleFoundInB1( ce, isGet, temp );
break;
case _B2_:
temp = handleFoundInB2( ce, isGet, temp );
break;
}
}
else
{
/* Element is not in cache */
isHit = false;
if ( isGet )
{
missCnt++;
}
if ( log.isDebugEnabled() )
{
log.debug( "Element is not in cache" );
}
}
// ////////////////////////////////////////////////////////////////////////////
// Do some size Checks if this is a put
if ( !isGet && !isHit )
{
if ( T1.size() + B1.size() >= maxSize )
{
/* B1 + T1 full? */
if ( T1.size() < maxSize )
{
/* Still room in T1? */
temp = (ElementDescriptor) B1.removeLast();
if ( temp != null )
{
map.remove( temp.key );
}
/* yes: take page off B1 */
// temp->pointer = replace(); /* find new place to put page
// */
replace( temp );
}
else
{
/* no: B1 must be empty */
temp = (ElementDescriptor) T1.removeLast(); /*
* take page //
* off // T1
*/
map.remove( temp.ce.getKey() );
// if (temp->dirty) destage(temp); /* if dirty, evict before
// overwrite */
replace( temp );
}
}
else
{
/* B1 + T1 have less than the maxSize elements */
if ( T1.size() + T2.size() + B1.size() + B2.size() >= maxSize )
{
/* cache full? */
/* Yes, cache full: */
if ( T1.size() + T2.size() + B1.size() + B2.size() >= 2 * maxSize )
{
/* cache is full: */
/* x find and reuse B2�s LRU */
temp = (ElementDescriptor) B2.removeLast();
if ( temp != null )
{
map.remove( temp.key );
}
}
else
{
/* cache directory not full, easy case */
// nop
}
replace( temp );
}
else
{
/* cache not full, easy case */
// nop
}
}
}
if ( !isGet && !isHit )
{
temp = new ElementDescriptor( ce );
temp.ce = ce;
temp.listNum = _T1_;
T1.addFirst( temp );
// seen once recently, put on T1
this.map.put( temp.ce.getKey(), temp );
}
// end if put
if ( temp == null )
{
return null;
}
return temp.ce;
}