public void replace()

in src/experimental/org/apache/commons/jcs/engine/memory/arc/ARCMemoryCache.java [514:603]


    public void replace( ElementDescriptor orig )
    {
        try
        {
            ElementDescriptor temp;
            if ( T1.size() >= Math.max( 1, target_T1 ) )
            {
                // T1�s size exceeds target?
                // yes: T1 is too big
                temp = (ElementDescriptor) T1.getLast();
                if ( orig == null || !orig.key.equals( temp.key ) )
                {
                    if ( log.isDebugEnabled() )
                    {
                        log.debug( "replace -- T1 to B1" );
                        log.debug( getStats() );
                    }
                    temp = (ElementDescriptor) T1.removeLast(); // grab LRU from
                    // T1
                    // nullify object, temp is now just a dummy container to
                    // help adjust the lru size
                    try
                    {
                        this.waterfal( temp.ce );
                    }
                    catch ( Exception e )
                    {
                        log.error( e );
                    }
                    temp.ce = null;
                    temp.listNum = _B1_; // note that fact
                    B1.addFirst( temp ); // put it on B1
                    // T1Length�; B1Length++; // bookkeep
                }
                else
                {
                    if ( log.isDebugEnabled() )
                    {
                        log.debug( "orig == temp, t1" );
                    }
                }
            }
            else
            // if t2 is greater than or equal to what is left in c after the
            // target
            if ( ( T2.size() + T1.size() ) > maxSize )
            {

                // no: T1 is not too big
                temp = (ElementDescriptor) T2.getLast();
                if ( orig == null || !orig.key.equals( temp.key ) )
                {
                    if ( log.isDebugEnabled() )
                    {
                        log.debug( "replace -- T2 to B2" );
                        log.debug( getStats() );
                    }

                    temp = (ElementDescriptor) T2.removeLast(); // grab LRU page
                    // of T2
                    // nullify object, temp is now just a dummy container to
                    // help
                    // adjust the lru size
                    try
                    {
                        this.waterfal( temp.ce );
                    }
                    catch ( Exception e )
                    {
                        log.error( e );
                    }
                    temp.ce = null;
                    temp.listNum = _B2_; // note that fact
                    B2.addFirst( temp ); // put it on B2
                    // T2Length�; B2Length++; // bookkeep
                }
                else
                {
                    if ( log.isDebugEnabled() )
                    {
                        log.debug( "orig == temp, t2" );
                    }
                }
            }
        }
        catch ( Exception e )
        {
            log.error( e );
        }
    }