ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
APC.php
Go to the documentation of this file.
1 <?php
37 
44  private $_cachePrefix = null;
45 
52  private $_cacheTime = 600;
53 
54 
63  protected function _storeData() {
64  if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
65  $this->_currentObject->detach();
66 
67  if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) {
68  $this->__destruct();
69  throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in APC');
70  }
71  $this->_currentCellIsDirty = false;
72  }
73  $this->_currentObjectID = $this->_currentObject = null;
74  } // function _storeData()
75 
76 
86  public function addCacheData($pCoord, PHPExcel_Cell $cell) {
87  if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
88  $this->_storeData();
89  }
90  $this->_cellCache[$pCoord] = true;
91 
92  $this->_currentObjectID = $pCoord;
93  $this->_currentObject = $cell;
94  $this->_currentCellIsDirty = true;
95 
96  return $cell;
97  } // function addCacheData()
98 
99 
108  public function isDataSet($pCoord) {
109  // Check if the requested entry is the current object, or exists in the cache
110  if (parent::isDataSet($pCoord)) {
111  if ($this->_currentObjectID == $pCoord) {
112  return true;
113  }
114  // Check if the requested entry still exists in apc
115  $success = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
116  if ($success === FALSE) {
117  // Entry no longer exists in APC, so clear it from the cache array
118  parent::deleteCacheData($pCoord);
119  throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
120  }
121  return true;
122  }
123  return false;
124  } // function isDataSet()
125 
126 
135  public function getCacheData($pCoord) {
136  if ($pCoord === $this->_currentObjectID) {
137  return $this->_currentObject;
138  }
139  $this->_storeData();
140 
141  // Check if the entry that has been requested actually exists
142  if (parent::isDataSet($pCoord)) {
143  $obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
144  if ($obj === FALSE) {
145  // Entry no longer exists in APC, so clear it from the cache array
146  parent::deleteCacheData($pCoord);
147  throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
148  }
149  } else {
150  // Return null if requested entry doesn't exist in cache
151  return null;
152  }
153 
154  // Set current entry to the requested entry
155  $this->_currentObjectID = $pCoord;
156  $this->_currentObject = unserialize($obj);
157  // Re-attach this as the cell's parent
158  $this->_currentObject->attach($this);
159 
160  // Return requested entry
161  return $this->_currentObject;
162  } // function getCacheData()
163 
164 
170  public function getCellList() {
171  if ($this->_currentObjectID !== null) {
172  $this->_storeData();
173  }
174 
175  return parent::getCellList();
176  }
177 
178 
186  public function deleteCacheData($pCoord) {
187  // Delete the entry from APC
188  apc_delete($this->_cachePrefix.$pCoord.'.cache');
189 
190  // Delete the entry from our cell address array
191  parent::deleteCacheData($pCoord);
192  } // function deleteCacheData()
193 
194 
203  public function copyCellCollection(PHPExcel_Worksheet $parent) {
204  parent::copyCellCollection($parent);
205  // Get a new id for the new file name
206  $baseUnique = $this->_getUniqueID();
207  $newCachePrefix = substr(md5($baseUnique),0,8).'.';
208  $cacheList = $this->getCellList();
209  foreach($cacheList as $cellID) {
210  if ($cellID != $this->_currentObjectID) {
211  $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache');
212  if ($obj === FALSE) {
213  // Entry no longer exists in APC, so clear it from the cache array
214  parent::deleteCacheData($cellID);
215  throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in APC');
216  }
217  if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) {
218  $this->__destruct();
219  throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in APC');
220  }
221  }
222  }
223  $this->_cachePrefix = $newCachePrefix;
224  } // function copyCellCollection()
225 
226 
232  public function unsetWorksheetCells() {
233  if ($this->_currentObject !== NULL) {
234  $this->_currentObject->detach();
235  $this->_currentObject = $this->_currentObjectID = null;
236  }
237 
238  // Flush the APC cache
239  $this->__destruct();
240 
241  $this->_cellCache = array();
242 
243  // detach ourself from the worksheet, so that it can then delete this object successfully
244  $this->_parent = null;
245  } // function unsetWorksheetCells()
246 
247 
254  public function __construct(PHPExcel_Worksheet $parent, $arguments) {
255  $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
256 
257  if ($this->_cachePrefix === NULL) {
258  $baseUnique = $this->_getUniqueID();
259  $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
260  $this->_cacheTime = $cacheTime;
261 
262  parent::__construct($parent);
263  }
264  } // function __construct()
265 
266 
270  public function __destruct() {
271  $cacheList = $this->getCellList();
272  foreach($cacheList as $cellID) {
273  apc_delete($this->_cachePrefix.$cellID.'.cache');
274  }
275  } // function __destruct()
276 
277 
284  public static function cacheMethodIsAvailable() {
285  if (!function_exists('apc_store')) {
286  return FALSE;
287  }
288  if (apc_sma_info() === FALSE) {
289  return FALSE;
290  }
291 
292  return TRUE;
293  }
294 
295 }
copyCellCollection(PHPExcel_Worksheet $parent)
Clone the cell collection.
Definition: APC.php:203
addCacheData($pCoord, PHPExcel_Cell $cell)
Add or Update a cell in cache identified by coordinate address.
Definition: APC.php:86
unsetWorksheetCells()
Clear the cell collection and disconnect from our parent.
Definition: APC.php:232
getCellList()
Get a list of all cell addresses currently held in cache.
Definition: APC.php:170
static cacheMethodIsAvailable()
Identify whether the caching method is currently available Some methods are dependent on the availabi...
Definition: APC.php:284
__destruct()
Destroy this cell collection.
Definition: APC.php:270
$success
Definition: Utf8Test.php:86
_getUniqueID()
Generate a unique ID for cache referencing.
Definition: CacheBase.php:311
__construct(PHPExcel_Worksheet $parent, $arguments)
Initialise this new cell collection.
Definition: APC.php:254
Create styles array
The data for the language used.
_storeData()
Store cell data in cache for the current cell object if it&#39;s "dirty", and the &#39;nullify&#39; the current c...
Definition: APC.php:63
deleteCacheData($pCoord)
Delete a cell in cache identified by coordinate address.
Definition: APC.php:186
isDataSet($pCoord)
Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
Definition: APC.php:108
getCacheData($pCoord)
Get cell at a specific coordinate.
Definition: APC.php:135