webengine/osswebengine/cache/src/HttpCacheEvictionHandler.cpp
changeset 10 a359256acfc6
parent 1 7c90e6132015
child 11 c8a366e56285
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Implementation of CHttpCacheEvictionHandler 
    14 * Description:  Implementation of CHttpCacheEvictionHandler
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include "HttpCacheEvictionHandler.h"
    19 #include "HttpCacheEvictionHandler.h"
   109 
   109 
   110 // Destructor
   110 // Destructor
   111 CHttpCacheEvictionHandler::~CHttpCacheEvictionHandler()
   111 CHttpCacheEvictionHandler::~CHttpCacheEvictionHandler()
   112     {
   112     {
   113     if (iBuckets)
   113     if (iBuckets)
   114         {    	
   114         {
   115 	    // delete the entries    
   115         // delete the entries
   116 	    for( TInt i=0; i<iBuckets->Count(); ++i )
   116         for( TInt i=0; i<iBuckets->Count(); ++i )
   117 	        delete iBuckets->At( i );	   
   117             delete iBuckets->At( i );
   118         }        
   118         }
   119         delete iBuckets;
   119         delete iBuckets;
   120     }
   120     }
   121 
   121 
   122 // -----------------------------------------------------------------------------
   122 // -----------------------------------------------------------------------------
   123 // CHttpCacheEvictionHandler::InsertL
   123 // CHttpCacheEvictionHandler::InsertL
   335                     candidate = entry;
   335                     candidate = entry;
   336                     }
   336                     }
   337                 }
   337                 }
   338             }
   338             }
   339 
   339 
   340         // remove from the bucket, add it to the evicted list, 
   340         // remove from the bucket, add it to the evicted list,
   341         // reduce space needed size
   341         // reduce space needed size
   342         if ( candidate )
   342         if ( candidate )
   343             {
   343             {
   344 #ifdef __CACHELOG__
   344 #ifdef __CACHELOG__
   345             // no protected entries should be evacuated
   345             // no protected entries should be evacuated
   346             if( candidate->Protected() )
   346             if( candidate->Protected() )
   347             	{
   347                 {
   348 	            HttpCacheUtil::WriteUrlToLog( 0, _L( "CHttpCacheEvictionHandler::EvictL - PROTECTED entry is about to be removed" ), candidate->Url() );
   348                 HttpCacheUtil::WriteUrlToLog( 0, _L( "CHttpCacheEvictionHandler::EvictL - PROTECTED entry is about to be removed" ), candidate->Url() );
   349             	}
   349                 }
   350 
   350 
   351             HttpCacheUtil::WriteLogFilenameAndUrl( 0,
   351             HttpCacheUtil::WriteLogFilenameAndUrl( 0,
   352                                            _L("CHttpCacheEvictionHandler::EvictL - removing entry "),
   352                                            _L("CHttpCacheEvictionHandler::EvictL - removing entry "),
   353                                            candidate->Filename(),
   353                                            candidate->Filename(),
   354                                            candidate->Url(),
   354                                            candidate->Url(),
   355                                            candidate->BodySize(), 
   355                                            candidate->BodySize(),
   356                                            ELogEntrySize );
   356                                            ELogEntrySize );
   357 #endif //__CACHELOG__
   357 #endif //__CACHELOG__
   358             
   358 
   359             iBuckets->At( bucketInd )->Remove( *candidate );
   359             iBuckets->At( bucketInd )->Remove( *candidate );
   360             // Reduce size needed
   360             // Reduce size needed
   361             aSpaceNeeded -= candidate->BodySize();
   361             aSpaceNeeded -= candidate->BodySize();
   362             aSpaceNeeded -= candidate->HeaderSize();
   362             aSpaceNeeded -= candidate->HeaderSize();
   363 
   363 
   364             evictedEntries->AppendL( candidate );
   364             evictedEntries->AppendL( candidate );
   365 
   365 
   366 #ifdef __CACHELOG__
   366 #ifdef __CACHELOG__
   367             if ( aSpaceNeeded > 0 ) {
   367             if ( aSpaceNeeded > 0 ) {
   368                 HttpCacheUtil::WriteLog( 0, _L( "CHttpCacheEvictionHandler::EvictL - more space needed aSpaceNeeded = " ), aSpaceNeeded );
   368                 HttpCacheUtil::WriteLog( 0, _L( "CHttpCacheEvictionHandler::EvictL - more space needed aSpaceNeeded = " ), aSpaceNeeded );
   369             	}
   369                 }
   370 #endif
   370 #endif
   371             }
   371             }
   372         else
   372         else
   373             {
   373             {
   374             // no candidate no free
   374             // no candidate no free
   472         {
   472         {
   473         HttpCacheUtil::WriteLogFilenameAndUrl( 0,
   473         HttpCacheUtil::WriteLogFilenameAndUrl( 0,
   474                                            _L("CHttpCacheEvictionHandler::ItemIsInBucket - entry NOT found"),
   474                                            _L("CHttpCacheEvictionHandler::ItemIsInBucket - entry NOT found"),
   475                                            aCacheEntry.Filename(),
   475                                            aCacheEntry.Filename(),
   476                                            aCacheEntry.Url(),
   476                                            aCacheEntry.Url(),
   477                                            aCacheEntry.BodySize(), 
   477                                            aCacheEntry.BodySize(),
   478                                            ELogEntrySize );
   478                                            ELogEntrySize );
   479         }
   479         }
   480 #endif // __CACHELOG__
   480 #endif // __CACHELOG__
   481 
   481 
   482     return found;
   482     return found;
   509         HttpCacheUtil::WriteLog( 0, _L( "------------------------------" ), i );
   509         HttpCacheUtil::WriteLog( 0, _L( "------------------------------" ), i );
   510 
   510 
   511         TBucketIter bucketIter( *(iBuckets->At( i )) );
   511         TBucketIter bucketIter( *(iBuckets->At( i )) );
   512         //
   512         //
   513         bucketIter.SetToFirst();
   513         bucketIter.SetToFirst();
   514         while( ( entry = bucketIter++ ) != NULL )
   514         while ( ( entry = bucketIter++ ) != NULL )
   515             {
   515             {
   516             _LIT( KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
   516             _LIT( KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
   517             _LIT( KRefSizeString,"CHttpCacheEvictionHandler::LogBuckets - size: %d refcount:%d");
   517             _LIT( KRefSizeString,"CHttpCacheEvictionHandler::LogBuckets - size: %d refcount:%d");
   518 
   518 
   519             TBuf<50> refStr;
   519             // note ref string is 60 chars before we format it
       
   520             TBuf<80> refStr;
   520             TBuf<50> lastAccessedStr;
   521             TBuf<50> lastAccessedStr;
   521 
   522 
   522             TTime lastAccessed( entry->LastAccessed() );
   523             TTime lastAccessed( entry->LastAccessed() );
   523             TRAP_IGNORE( lastAccessed.FormatL( lastAccessedStr, KDateString ) );
   524             TRAP_IGNORE( lastAccessed.FormatL( lastAccessedStr, KDateString ) );
   524             // add size/refcount
   525             // add size/refcount
   527             HttpCacheUtil::WriteLog( 0, lastAccessedStr );
   528             HttpCacheUtil::WriteLog( 0, lastAccessedStr );
   528             HttpCacheUtil::WriteLogFilenameAndUrl( 0,
   529             HttpCacheUtil::WriteLogFilenameAndUrl( 0,
   529                                                _L("CHttpCacheEvictionHandler::LogBuckets - "),
   530                                                _L("CHttpCacheEvictionHandler::LogBuckets - "),
   530                                                entry->Filename(),
   531                                                entry->Filename(),
   531                                                entry->Url(),
   532                                                entry->Url(),
   532                                                i, 
   533                                                i,
   533                                                ELogBucketIndex );
   534                                                ELogBucketIndex );
   534             }
   535             }
   535         }
   536         }
   536     }
   537     }
   537 #endif // __CACHELOG__
   538 #endif // __CACHELOG__