PageCache Class Reference

Provides an LRU cache designed to provide faster access to pages if such a page has already been read. More...

#include <PageCache.h>

List of all members.

Public Types

typedef std::list
< CachedPage::UnitPtr
UnitList

Public Member Functions

 PageCache (const size_t maxCacheSize=20000000)
 ~PageCache ()
CachedPage::UnitPtr getUnit (DataRequest *pOriginalRequest, DimensionDescriptor startRow, DimensionDescriptor startBand)
void initialize (int bytesPerBand, int columnCount, int bandCount)
CachedPagecreatePage (CachedPage::UnitPtr pUnit, InterleaveFormatType requestedFormat, DimensionDescriptor startRow, DimensionDescriptor startColumn, DimensionDescriptor startBand)

Protected Member Functions

void enforceCacheSize ()

Protected Attributes

const size_t MAX_CACHE_SIZE
UnitList mUnits
std::string mFilename
size_t mCacheSize
int mBytesPerBand
int mColumnCount
int mBandCount


Detailed Description

Provides an LRU cache designed to provide faster access to pages if such a page has already been read.

For example, a multi-threaded algorithm could get a DataAccessor to odd and even rows. These two threads would be able to share the same page.

When clearing units from the cache, it simply removed the oldest units from the cache. It is possible that a CachedPage still holds a reference to the released unit. Since the units are consistently referred to with shared_ptrs, the actual memory will not be released until the last page is destroyed. This does, however, allow duplicate units -- one that the cache knows about, and one that a lingering CachedPage references.

Definition at line 39 of file PageCache.h.


Member Typedef Documentation

An STL list of PagePtr.

This list is provided in such a fashion so that calling std::list<UnitPtr>::erase() on an iterator will also delete the CacheUnit properly if it is the last reference.

Definition at line 75 of file PageCache.h.


Constructor & Destructor Documentation

PageCache::PageCache ( const size_t  maxCacheSize = 20000000  ) 

Creates a thread-safe LRU PageCache.

Parameters:
maxCacheSize The maximum size of the cache in bytes.

PageCache::~PageCache (  ) 

Destroys the thread-safe LRU PageCache.


Member Function Documentation

CachedPage::UnitPtr PageCache::getUnit ( DataRequest pOriginalRequest,
DimensionDescriptor  startRow,
DimensionDescriptor  startBand 
)

Fetches a unit from the cache.

See RasterPager::getPage() for details on the parameters.

Returns:
A CacheUnit object containing the startRow, startColumn, and startBand, and containing and least concurrentRows number of rows, concurrentColumns number of columns, and concurrentBands number of bands.

void PageCache::initialize ( int  bytesPerBand,
int  columnCount,
int  bandCount 
)

Initializes member variables of the cache & resets hit/miss counts.

This must be done after construction of the cache.

Parameters:
bytesPerBand The number of bytes each element takes up. Requires the value contained by RasterDataDescriptor::getBytesPerElement().
columnCount The number of columns in file on disk.
bandCount The number of bands in the file on disk.

CachedPage* PageCache::createPage ( CachedPage::UnitPtr  pUnit,
InterleaveFormatType  requestedFormat,
DimensionDescriptor  startRow,
DimensionDescriptor  startColumn,
DimensionDescriptor  startBand 
)

Create a CachedPage for the given cache unit.

Parameters:
pUnit The unit to create the page for.
requestedFormat The format of the page provided.
startRow The desired row.
startColumn The desired column.
startBand The desired band.
Returns:
The created page, or NULL if pUnit is NULL. The caller takes ownership over the created page.

void PageCache::enforceCacheSize (  )  [protected]


Member Data Documentation

const size_t PageCache::MAX_CACHE_SIZE [protected]

Definition at line 113 of file PageCache.h.

Definition at line 114 of file PageCache.h.

std::string PageCache::mFilename [protected]

Definition at line 115 of file PageCache.h.

size_t PageCache::mCacheSize [protected]

Definition at line 116 of file PageCache.h.

int PageCache::mBytesPerBand [protected]

Definition at line 117 of file PageCache.h.

int PageCache::mColumnCount [protected]

Definition at line 118 of file PageCache.h.

int PageCache::mBandCount [protected]

Definition at line 119 of file PageCache.h.


Software Development Kit - Opticks 4.9.0 Build 16218