Sirikata
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
Sirikata::Transfer::CacheLayer Class Reference

Base class for cache layer--will try a next cache and respond with the data to any previous cache layers so they can store that data as well. More...

#include <CacheLayer.hpp>

Inheritance diagram for Sirikata::Transfer::CacheLayer:
Collaboration diagram for Sirikata::Transfer::CacheLayer:

List of all members.

Classes

struct  CacheEntry

Public Member Functions

virtual ~CacheLayer ()
 CacheLayer (CacheLayer *tryNext)
 Constructor needs to know what cache layer to try next, and what to return to.
void setRespondTo (CacheLayer *newRespond)
void setNext (CacheLayer *newNext)
 If you want to change the ordering of the cache layers.
CacheLayergetNext () const
CacheLayergetResponder () const
void addToCache (const Fingerprint &fileId, const DenseDataPtr &data)
virtual void purgeFromCache (const Fingerprint &fileId)
 Purges this hash from all subsequent caches.
virtual void getData (const Fingerprint &fileId, const Range &requestedRange, const TransferCallback &callback)
 Query this cache layer.

Protected Member Functions

void populateParentCaches (const Fingerprint &fileId, const DenseDataPtr &data)
 Goes up the heirararchy of cache layers filling in data.
virtual void destroyCacheEntry (const Fingerprint &fileId, CacheEntry *cacheLayerData, cache_usize_type releaseSize)
 Called after a cache entry has been destroyed-- Does not remove the item from other caches in the chain.
virtual void populateCache (const Fingerprint &fileId, const DenseDataPtr &data)
 Goes up the heirararchy of cache layers filling in data.

Private Member Functions

void setResponder (CacheLayer *other)

Private Attributes

CacheLayermRespondTo
CacheLayermNext

Friends

class CacheMap

Detailed Description

Base class for cache layer--will try a next cache and respond with the data to any previous cache layers so they can store that data as well.


Constructor & Destructor Documentation

virtual Sirikata::Transfer::CacheLayer::~CacheLayer ( ) [inline, virtual]

References mNext, and setResponder().

Sirikata::Transfer::CacheLayer::CacheLayer ( CacheLayer tryNext) [inline]

Constructor needs to know what cache layer to try next, and what to return to.

References setResponder().


Member Function Documentation

void Sirikata::Transfer::CacheLayer::addToCache ( const Fingerprint fileId,
const DenseDataPtr data 
) [inline]

References addToCache(), mNext, and populateCache().

Referenced by addToCache().

virtual void Sirikata::Transfer::CacheLayer::destroyCacheEntry ( const Fingerprint fileId,
CacheEntry cacheLayerData,
cache_usize_type  releaseSize 
) [inline, protected, virtual]

Called after a cache entry has been destroyed-- Does not remove the item from other caches in the chain.

Should be called only from CacheMap.

Reimplemented in Sirikata::Transfer::DiskCacheLayer, and Sirikata::Transfer::MemoryCacheLayer.

Referenced by Sirikata::Transfer::CacheMap::destroyCacheLayerEntry().

virtual void Sirikata::Transfer::CacheLayer::getData ( const Fingerprint fileId,
const Range requestedRange,
const TransferCallback callback 
) [inline, virtual]

Query this cache layer.

If successful, call callback with the data and also call populateCache in order to populate the previous cache levels.

Parameters:
fidA unique identifier corresponding to the file (contains a hash).
requestedRangeA Range object specifying a single range that you need.
callbackTo be called with the data if successful, or NULL if failed.
Returns:
false, if the callback happened synchronously (i.e. in memory cache)

Reimplemented in Sirikata::Transfer::DiskCacheLayer, and Sirikata::Transfer::MemoryCacheLayer.

References getData(), and mNext.

Referenced by Sirikata::Transfer::DiskCacheLayer::getData(), and getData().

CacheLayer* Sirikata::Transfer::CacheLayer::getNext ( ) const [inline]

References mNext.

CacheLayer* Sirikata::Transfer::CacheLayer::getResponder ( ) const [inline]

References mRespondTo.

virtual void Sirikata::Transfer::CacheLayer::populateCache ( const Fingerprint fileId,
const DenseDataPtr data 
) [inline, protected, virtual]

Goes up the heirararchy of cache layers filling in data.

Parameters:
fileIdthe Fingerprint to store this data in CacheMap.
dataData to be stored in this CacheLayer.

Reimplemented in Sirikata::Transfer::DiskCacheLayer, and Sirikata::Transfer::MemoryCacheLayer.

References populateParentCaches().

Referenced by addToCache(), and populateParentCaches().

void Sirikata::Transfer::CacheLayer::populateParentCaches ( const Fingerprint fileId,
const DenseDataPtr data 
) [inline, protected]

Goes up the heirararchy of cache layers filling in data.

Note that you must *NOT* call the callback until you have populated the cache.

Todo:
: Handle two requests for the same chunk at the same time.

References mRespondTo, and populateCache().

Referenced by Sirikata::Transfer::MemoryCacheLayer::getData(), Sirikata::Transfer::MemoryCacheLayer::populateCache(), Sirikata::Transfer::DiskCacheLayer::populateCache(), populateCache(), and Sirikata::Transfer::DiskCacheLayer::workerThread().

virtual void Sirikata::Transfer::CacheLayer::purgeFromCache ( const Fingerprint fileId) [inline, virtual]

Purges this hash from all subsequent caches.

In general, it is not useful to do this manually, since the CachePolicy handles freeing extra data, and it is usually assumed that the cache is correct.

Validity checking should probably be added elsewhere--though it is not really feasable for incomplete downloads if we used a range.

Reimplemented in Sirikata::Transfer::DiskCacheLayer, and Sirikata::Transfer::MemoryCacheLayer.

References mNext, and purgeFromCache().

Referenced by Sirikata::Transfer::DiskCacheLayer::purgeFromCache(), and purgeFromCache().

void Sirikata::Transfer::CacheLayer::setNext ( CacheLayer newNext) [inline]

If you want to change the ordering of the cache layers.

This may be safe, but it's probably not smart to use except when constructing or destroying a CacheLayer.

References mNext, and setResponder().

void Sirikata::Transfer::CacheLayer::setResponder ( CacheLayer other) [inline, private]

References mRespondTo.

Referenced by CacheLayer(), setNext(), and ~CacheLayer().

void Sirikata::Transfer::CacheLayer::setRespondTo ( CacheLayer newRespond) [inline]

References mRespondTo.


Friends And Related Function Documentation

friend class CacheMap [friend]

Member Data Documentation


The documentation for this class was generated from the following file: