Sirikata
|
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>
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. | |
CacheLayer * | getNext () const |
CacheLayer * | getResponder () 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 | |
CacheLayer * | mRespondTo |
CacheLayer * | mNext |
Friends | |
class | CacheMap |
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.
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().
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.
fid | A unique identifier corresponding to the file (contains a hash). |
requestedRange | A Range object specifying a single range that you need. |
callback | To be called with the data if successful, or NULL if failed. |
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.
fileId | the Fingerprint to store this data in CacheMap. |
data | Data 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.
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.
friend class CacheMap [friend] |
CacheLayer* Sirikata::Transfer::CacheLayer::mNext [private] |
Referenced by addToCache(), getData(), getNext(), purgeFromCache(), setNext(), and ~CacheLayer().
Referenced by getResponder(), populateParentCaches(), setResponder(), and setRespondTo().