PHPExcel_CachedObjectStorage
[ class tree: PHPExcel_CachedObjectStorage ] [ index: PHPExcel_CachedObjectStorage ] [ all elements ]

Source for file Wincache.php

Documentation is available at Wincache.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_CachedObjectStorage
  23.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.3c, 2010-06-01
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_CachedObjectStorage_Wincache
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_CachedObjectStorage
  34.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36.  
  37.     private $_cachePrefix null;
  38.  
  39.     private $_cacheTime 600;
  40.  
  41.  
  42.     private function _storeData({
  43.         $this->_currentObject->detach();
  44.  
  45.         $obj serialize($this->_currentObject);
  46.         if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
  47.             wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache'$obj$this->_cacheTime);
  48.         else {
  49.             wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache'$obj$this->_cacheTime);
  50.         }
  51.  
  52.         $this->_currentObjectID = $this->_currentObject = null;
  53.     }    //    function _storeData()
  54.  
  55.  
  56.     /**
  57.      *    Add or Update a cell in cache identified by coordinate address
  58.      *
  59.      *    @param    string            $pCoord        Coordinate address of the cell to update
  60.      *    @param    PHPExcel_Cell    $cell        Cell to update
  61.      *    @return    void 
  62.      *    @throws    Exception
  63.      */
  64.     public function addCacheData($pCoordPHPExcel_Cell $cell{
  65.         if (($pCoord !== $this->_currentObjectID&& ($this->_currentObjectID !== null)) {
  66.             $this->_storeData();
  67.         }
  68.         $this->_cellCache[$pCoordtrue;
  69.  
  70.         $this->_currentObjectID = $pCoord;
  71.         $this->_currentObject = $cell;
  72.  
  73.         return $cell;
  74.     }    //    function addCacheData()
  75.  
  76.  
  77.     /**
  78.      *    Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
  79.      *
  80.      *    @param    string        $pCoord        Coordinate address of the cell to check
  81.      *    @return    void 
  82.      *    @return    boolean 
  83.      */
  84.     public function isDataSet($pCoord{
  85.         //    Check if the requested entry is the current object, or exists in the cache
  86.         if (parent::isDataSet($pCoord)) {
  87.             if ($this->_currentObjectID == $pCoord{
  88.                 return true;
  89.             }
  90.             //    Check if the requested entry still exists in cache
  91.             $success wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache');
  92.             if ($success === false{
  93.                 //    Entry no longer exists in Wincache, so clear it from the cache array
  94.                 parent::deleteCacheData($pCoord);
  95.                 throw new Exception('Cell entry no longer exists in Wincache');
  96.             }
  97.             return true;
  98.         }
  99.         return false;
  100.     }    //    function isDataSet()
  101.  
  102.  
  103.     /**
  104.      * Get cell at a specific coordinate
  105.      *
  106.      * @param    string            $pCoord        Coordinate of the cell
  107.      * @throws    Exception
  108.      * @return    PHPExcel_Cell    Cell that was found, or null if not found
  109.      */
  110.     public function getCacheData($pCoord{
  111.         if ($pCoord === $this->_currentObjectID{
  112.             return $this->_currentObject;
  113.         }
  114.         $this->_storeData();
  115.  
  116.         //    Check if the entry that has been requested actually exists
  117.         $obj null;
  118.         if (parent::isDataSet($pCoord)) {
  119.             $success false;
  120.             $obj wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache'$success);
  121.             if ($success === false{
  122.                 //    Entry no longer exists in Wincache, so clear it from the cache array
  123.                 parent::deleteCacheData($pCoord);
  124.                 throw new Exception('Cell entry no longer exists in Wincache');
  125.             }
  126.         else {
  127.             //    Return null if requested entry doesn't exist in cache
  128.             return null;
  129.         }
  130.  
  131.         //    Set current entry to the requested entry
  132.         $this->_currentObjectID = $pCoord;
  133.         $this->_currentObject = unserialize($obj);
  134.         //    Re-attach the parent worksheet
  135.         $this->_currentObject->attach($this->_parent);
  136.  
  137.         //    Return requested entry
  138.         return $this->_currentObject;
  139.     }    //    function getCacheData()
  140.  
  141.  
  142.     /**
  143.      *    Delete a cell in cache identified by coordinate address
  144.      *
  145.      *    @param    string            $pCoord        Coordinate address of the cell to delete
  146.      *    @throws    Exception
  147.      */
  148.     public function deleteCacheData($pCoord{
  149.         //    Delete the entry from Wincache
  150.         wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache');
  151.  
  152.         //    Delete the entry from our cell address array
  153.         parent::deleteCacheData($pCoord);
  154.     }    //    function deleteCacheData()
  155.  
  156.  
  157.     public function unsetWorksheetCells({
  158.         if(!is_null($this->_currentObject)) {
  159.             $this->_currentObject->detach();
  160.             $this->_currentObject = $this->_currentObjectID = null;
  161.         }
  162.  
  163.         //    Flush the Wincache cache
  164.         $this->__destruct();
  165.  
  166.         $this->_cellCache = array();
  167.  
  168.         //    detach ourself from the worksheet, so that it can then delete this object successfully
  169.         $this->_parent = null;
  170.     }    //    function unsetWorksheetCells()
  171.  
  172.  
  173.     public function __construct(PHPExcel_Worksheet $parent$arguments{
  174.         $cacheTime    (isset($arguments['cacheTime']))    $arguments['cacheTime']    600;
  175.  
  176.         if (is_null($this->_cachePrefix)) {
  177.             if (function_exists('posix_getpid')) {
  178.                 $baseUnique posix_getpid();
  179.             else {
  180.                 $baseUnique mt_rand();
  181.             }
  182.             $this->_cachePrefix substr(md5(uniqid($baseUnique,true)),0,8).'.';
  183.             $this->_cacheTime $cacheTime;
  184.  
  185.             parent::__construct($parent);
  186.         }
  187.     }    //    function __construct()
  188.  
  189.  
  190.     public function __destruct({
  191.         $cacheList $this->getCellList();
  192.         foreach($cacheList as $cellID{
  193.             wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
  194.         }
  195.     }    //    function __destruct()
  196.  
  197. }
  198.  
  199.  
  200. ?>

Documentation generated on Tue, 01 Jun 2010 17:08:15 +0200 by phpDocumentor 1.4.3