General: Reduce cell caching overhead using dirty flag to ensure that cells are only rewritten to the cache if they have actually been changed

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@72227 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-04-25 14:25:53 +00:00
parent ff4daef39c
commit 5672f25ebf
9 changed files with 76 additions and 39 deletions

View File

@ -41,12 +41,15 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) { if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$cellID.' in APC'); throw new Exception('Failed to store cell '.$cellID.' in APC');
} }
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -67,6 +70,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -57,6 +57,13 @@ class PHPExcel_CachedObjectStorage_CacheBase {
protected $_currentObjectID = null; protected $_currentObjectID = null;
/**
* Flag indicating whether the currently active Cell requires saving
*
* @var boolean
*/
protected $_currentCellIsDirty = true;
/** /**
* An array of cells or cell pointers for the worksheet cells held in this cache, * An array of cells or cell pointers for the worksheet cells held in this cache,
* and indexed by their coordinate address within the worksheet * and indexed by their coordinate address within the worksheet
@ -118,6 +125,7 @@ class PHPExcel_CachedObjectStorage_CacheBase {
$this->_cellCache[$pCoord]->detach(); $this->_cellCache[$pCoord]->detach();
unset($this->_cellCache[$pCoord]); unset($this->_cellCache[$pCoord]);
} }
$this->_currentCellIsDirty = false;
} // function deleteCacheData() } // function deleteCacheData()

View File

@ -40,6 +40,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END); fseek($this->_fileHandle,0,SEEK_END);
@ -48,6 +49,8 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset 'sz' => ftell($this->_fileHandle) - $offset
); );
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -67,6 +70,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -43,6 +43,7 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$obj = serialize($this->_currentObject); $obj = serialize($this->_currentObject);
@ -52,6 +53,8 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
throw new Exception('Failed to store cell '.$cellID.' in MemCache'); throw new Exception('Failed to store cell '.$cellID.' in MemCache');
} }
} }
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -72,6 +75,7 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -36,9 +36,12 @@
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject)); $this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -58,6 +61,7 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -36,9 +36,12 @@
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject); $this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -58,6 +61,7 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -41,6 +41,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
private $_memoryCacheSize = null; private $_memoryCacheSize = null;
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END); fseek($this->_fileHandle,0,SEEK_END);
@ -49,6 +50,8 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset 'sz' => ftell($this->_fileHandle) - $offset
); );
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -68,6 +71,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -41,6 +41,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
private function _storeData() { private function _storeData() {
if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$obj = serialize($this->_currentObject); $obj = serialize($this->_currentObject);
@ -55,6 +56,8 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
throw new Exception('Failed to store cell '.$cellID.' in WinCache'); throw new Exception('Failed to store cell '.$cellID.' in WinCache');
} }
} }
$this->_currentCellIsDirty = false;
}
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() } // function _storeData()
@ -76,6 +79,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
$this->_currentObjectID = $pCoord; $this->_currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->_currentObject = $cell;
$this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() } // function addCacheData()

View File

@ -25,6 +25,7 @@
Fixed in SVN: Fixed in SVN:
- General: (MBaker) Fix to build to ensure that Examples are included with the documentation - General: (MBaker) Fix to build to ensure that Examples are included with the documentation
- General: (MBaker) Reduce cell caching overhead using dirty flag to ensure that cells are only rewritten to the cache if they have actually been changed
- Bugfix: (MBaker) Work item 15459 - Invalid cell coordinate in Autofilter for Excel2007 Writer - Bugfix: (MBaker) Work item 15459 - Invalid cell coordinate in Autofilter for Excel2007 Writer
- Bugfix: (MBaker) Work item 15518 - PCLZip library issue - Bugfix: (MBaker) Work item 15518 - PCLZip library issue
- Bugfix: (MBaker) Work item 15537 - Excel2007 Reader canRead function bug - Bugfix: (MBaker) Work item 15537 - Excel2007 Reader canRead function bug