Cache

The Cache class provides a global memory cache of previously retrieved URLs. More...

Publicly inherits QObject.

Public Methods

Cache( );
voidclear( );
boolgetUrl( Request* request, const Url& url, bool reload );
~Cache( );

Public Slots

voidconnDestroyed( );
voiddata( const char* bytes, int length );
voidendOfData( );
voidrequestDone( Request* req );
voidstartOfData( QString mediaType, QString mediaSubtype, int totalSize );

Protected Methods

voidtimerEvent( QTimerEvent* e );

Private Methods

CacheData*findActive( const Url& url );
CacheData*findActive( Connection* conn );
CacheData*findData( const Url& url );

Private Data Members

QList<CacheData>_active;
QList<CacheData>_data;
QList<Req>_pending;
QList<Req>_reqs;

Detailed Documentation

The Cache class provides a global memory cache of previously retrieved URLs.

The Cache is a global object that is used by the Request class to retrieve data, given a URL. As data is retrieved, it is stored in an in-memory cache for quick retrieval by future Requests. In addition, if multiple Requests ask for a URL that is in the process of beign retrieved, the Cache will automatically connect all of the Requests to a single Connection to improve efficiency.

The in-memory cache can grow to any size, and it is currently not limited. However, it can be manually cleared.

Public Methods Documentation

Cache ( );

Create a new Cache.

void clear ( );

Free all cached data.

bool getUrl ( Request* request, const Url& url, bool reload );

Process a request from a Request for a URL. If the requested URL has already been retrieved or is being retrieved, connect the Request to the existing CacheData. Otherwise, create a new CacheData and connection, and connect them to the Request.

~Cache ( );

Delete all cached data.

Public Slots Documentation

void connDestroyed ( );

The open connection has been destroyed for some reason. Remove the associated CacheData, as it is not complete.

void data ( const char* bytes, int length );

Append the incoming data to the associated CacheData object.

void endOfData ( );

Mark the data as complete, and store it in the cache. Data retrieved through the "file" method is not cached.

void requestDone ( Request* req );

Process the notification from a request that it has been aborted. If no other requests are waiting on the same data, abort the connection and delete the associated CacheData.

void startOfData ( QString mediaType, QString mediaSubtype, int totalSize );

Store the media type, and the total data length.

Protected Methods Documentation

void timerEvent ( QTimerEvent* e );

This is where Requests are actually connected with open Connections. For each pending Request, locate its associated CacheData. If the startOfData signal has already been received by the CacheData, forward the information to the Request now. If there is any existing data, forward it to the Request now. If the CacheData is complete, forward the endOfData signal to the Request now.

Private Methods Documentation

CacheData* findActive ( const Url& url );

Find the CacheData in the active list associated with the given URL.

CacheData* findActive ( Connection* conn );

Find the CacheData in the active list associated with the given connection.

CacheData* findData ( const Url& url );

Find the CacheData in the cache list associated with the given URL.


Return to Index.
Automatically generated on Aug 11 23:32