Wikibase
MediaWiki Wikibase extension
Wikibase\Lib\Store\ChunkCache Class Reference

Interface for DAO objects providing chunked access. More...

+ Inheritance diagram for Wikibase\Lib\Store\ChunkCache:
+ Collaboration diagram for Wikibase\Lib\Store\ChunkCache:

Public Member Functions

 __construct (ChunkAccess $source, $chunkSize, $maxSize)
 
 loadChunk ( $start, $size)
 Returns a chunk as a list of whatever object is used for data records by the implementing class. More...
 
 getRecordId ( $rec)
 Returns the sequential ID of the given data record. More...
 

Private Member Functions

 findEntryPosition ( $key)
 Finds the position for the given key in the internal entry array. More...
 
 insertChunk ( $start, $size, $before)
 
 prune ()
 Removes least recently used chunks until the total size is smaller than the max size specified in the constructor. More...
 

Private Attributes

 $source
 
 $entries = []
 
 $size = 0
 
 $maxSize
 
 $chunkSize
 
 $hitCount = 0
 
 $missCount = 0
 
 $modCount = 0
 

Detailed Description

Interface for DAO objects providing chunked access.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\Store\ChunkCache::__construct ( ChunkAccess  $source,
  $chunkSize,
  $maxSize 
)
Parameters
ChunkAccess$sourceThe source to load from
int$chunkSizeThe size of the chunk to load, if we have a choice
int$maxSizeThe maximum size this cache can grow to
Exceptions
MWException

Member Function Documentation

◆ findEntryPosition()

Wikibase\Lib\Store\ChunkCache::findEntryPosition (   $key)
private

Finds the position for the given key in the internal entry array.

This is implemented using iterative binary search.

Parameters
int$key
Returns
int the position if found, or the negative insert position minus one, if not.

◆ getRecordId()

Wikibase\Lib\Store\ChunkCache::getRecordId (   $rec)

Returns the sequential ID of the given data record.

Parameters
mixed$rec
Returns
int

Implements Wikibase\Lib\Store\ChunkAccess.

◆ insertChunk()

Wikibase\Lib\Store\ChunkCache::insertChunk (   $start,
  $size,
  $before 
)
private
Parameters
int$startthe ID to start loading at
int$sizethe maximum size of the chunk to load
int$beforeinsert into the internal entry list before this position.
Exceptions
MWException
Returns
array|bool the cache entry created by inserting the new chunk, or false if there is no more data to load from the source at the given position. The cache entry is an associative array containing the following keys:
  • start: the key the chunk starts at
  • data: a list of data records
  • next: the id the following chunk starts at (or after)
  • touched: (logical) timestamp of the entry's creation (taken from $this->modCount)

◆ loadChunk()

Wikibase\Lib\Store\ChunkCache::loadChunk (   $start,
  $size 
)

Returns a chunk as a list of whatever object is used for data records by the implementing class.

Parameters
int$startThe first ID in the chunk
int$sizeThe desired size of the chunk
Returns
array the desired chunk of rows/objects

Implements Wikibase\Lib\Store\ChunkAccess.

◆ prune()

Wikibase\Lib\Store\ChunkCache::prune ( )
private

Removes least recently used chunks until the total size is smaller than the max size specified in the constructor.

Member Data Documentation

◆ $chunkSize

Wikibase\Lib\Store\ChunkCache::$chunkSize
private

◆ $entries

Wikibase\Lib\Store\ChunkCache::$entries = []
private

◆ $hitCount

Wikibase\Lib\Store\ChunkCache::$hitCount = 0
private

◆ $maxSize

Wikibase\Lib\Store\ChunkCache::$maxSize
private

◆ $missCount

Wikibase\Lib\Store\ChunkCache::$missCount = 0
private

◆ $modCount

Wikibase\Lib\Store\ChunkCache::$modCount = 0
private

◆ $size

Wikibase\Lib\Store\ChunkCache::$size = 0
private

◆ $source

Wikibase\Lib\Store\ChunkCache::$source
private

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