web/lib/Zend/Cache/Core.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Cache
    16  * @package    Zend_Cache
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Core.php 24989 2012-06-21 07:24:13Z mabe $
    19  * @version    $Id$
    20  */
    20  */
    21 
    21 
    22 
    22 
    23 /**
    23 /**
    24  * @package    Zend_Cache
    24  * @package    Zend_Cache
    25  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    25  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    26  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    26  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    27  */
    27  */
    28 class Zend_Cache_Core
    28 class Zend_Cache_Core
    29 {
    29 {
    30     /**
    30     /**
   141         }
   141         }
   142         if (!is_array($options)) {
   142         if (!is_array($options)) {
   143             Zend_Cache::throwException("Options passed were not an array"
   143             Zend_Cache::throwException("Options passed were not an array"
   144             . " or Zend_Config instance.");
   144             . " or Zend_Config instance.");
   145         }
   145         }
   146         while (list($name, $value) = each($options)) {
   146         foreach ($options as $name => $value) {
   147             $this->setOption($name, $value);
   147             $this->setOption($name, $value);
   148         }
   148         }
   149         $this->_loggerSanity();
   149         $this->_loggerSanity();
   150     }
   150     }
   151 
   151 
   156      * @return Zend_Cache_Core
   156      * @return Zend_Cache_Core
   157      */
   157      */
   158     public function setConfig(Zend_Config $config)
   158     public function setConfig(Zend_Config $config)
   159     {
   159     {
   160         $options = $config->toArray();
   160         $options = $config->toArray();
   161         while (list($name, $value) = each($options)) {
   161         foreach ($options as $name => $value) {
   162             $this->setOption($name, $value);
   162             $this->setOption($name, $value);
   163         }
   163         }
   164         return $this;
   164         return $this;
   165     }
   165     }
   166 
   166 
   298         if (!$this->_options['caching']) {
   298         if (!$this->_options['caching']) {
   299             return false;
   299             return false;
   300         }
   300         }
   301         $id = $this->_id($id); // cache id may need prefix
   301         $id = $this->_id($id); // cache id may need prefix
   302         $this->_lastId = $id;
   302         $this->_lastId = $id;
   303         self::_validateIdOrTag($id);
   303         $this->_validateIdOrTag($id);
   304 
   304 
   305         $this->_log("Zend_Cache_Core: load item '{$id}'", 7);
   305         $this->_log("Zend_Cache_Core: load item '{$id}'", 7);
   306         $data = $this->_backend->load($id, $doNotTestCacheValidity);
   306         $data = $this->_backend->load($id, $doNotTestCacheValidity);
   307         if ($data===false) {
   307         if ($data===false) {
   308             // no cache available
   308             // no cache available
   325     {
   325     {
   326         if (!$this->_options['caching']) {
   326         if (!$this->_options['caching']) {
   327             return false;
   327             return false;
   328         }
   328         }
   329         $id = $this->_id($id); // cache id may need prefix
   329         $id = $this->_id($id); // cache id may need prefix
   330         self::_validateIdOrTag($id);
   330         $this->_validateIdOrTag($id);
   331         $this->_lastId = $id;
   331         $this->_lastId = $id;
   332 
   332 
   333         $this->_log("Zend_Cache_Core: test item '{$id}'", 7);
   333         $this->_log("Zend_Cache_Core: test item '{$id}'", 7);
   334         return $this->_backend->test($id);
   334         return $this->_backend->test($id);
   335     }
   335     }
   353         if ($id === null) {
   353         if ($id === null) {
   354             $id = $this->_lastId;
   354             $id = $this->_lastId;
   355         } else {
   355         } else {
   356             $id = $this->_id($id);
   356             $id = $this->_id($id);
   357         }
   357         }
   358         self::_validateIdOrTag($id);
   358         $this->_validateIdOrTag($id);
   359         self::_validateTagsArray($tags);
   359         $this->_validateTagsArray($tags);
   360         if ($this->_options['automatic_serialization']) {
   360         if ($this->_options['automatic_serialization']) {
   361             // we need to serialize datas before storing them
   361             // we need to serialize datas before storing them
   362             $data = serialize($data);
   362             $data = serialize($data);
   363         } else {
   363         } else {
   364             if (!is_string($data)) {
   364             if (!is_string($data)) {
   422     {
   422     {
   423         if (!$this->_options['caching']) {
   423         if (!$this->_options['caching']) {
   424             return true;
   424             return true;
   425         }
   425         }
   426         $id = $this->_id($id); // cache id may need prefix
   426         $id = $this->_id($id); // cache id may need prefix
   427         self::_validateIdOrTag($id);
   427         $this->_validateIdOrTag($id);
   428 
   428 
   429         $this->_log("Zend_Cache_Core: remove item '{$id}'", 7);
   429         $this->_log("Zend_Cache_Core: remove item '{$id}'", 7);
   430         return $this->_backend->remove($id);
   430         return $this->_backend->remove($id);
   431     }
   431     }
   432 
   432 
   458                                    Zend_Cache::CLEANING_MODE_MATCHING_TAG,
   458                                    Zend_Cache::CLEANING_MODE_MATCHING_TAG,
   459                                    Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG,
   459                                    Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG,
   460                                    Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) {
   460                                    Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) {
   461             Zend_Cache::throwException('Invalid cleaning mode');
   461             Zend_Cache::throwException('Invalid cleaning mode');
   462         }
   462         }
   463         self::_validateTagsArray($tags);
   463         $this->_validateTagsArray($tags);
   464 
   464 
   465         return $this->_backend->clean($mode, $tags);
   465         return $this->_backend->clean($mode, $tags);
   466     }
   466     }
   467 
   467 
   468     /**
   468     /**
   665      *
   665      *
   666      * @param  string $string Cache id or tag
   666      * @param  string $string Cache id or tag
   667      * @throws Zend_Cache_Exception
   667      * @throws Zend_Cache_Exception
   668      * @return void
   668      * @return void
   669      */
   669      */
   670     protected static function _validateIdOrTag($string)
   670     protected function _validateIdOrTag($string)
   671     {
   671     {
   672         if (!is_string($string)) {
   672         if (!is_string($string)) {
   673             Zend_Cache::throwException('Invalid id or tag : must be a string');
   673             Zend_Cache::throwException('Invalid id or tag : must be a string');
   674         }
   674         }
   675         if (substr($string, 0, 9) == 'internal-') {
   675         if (substr($string, 0, 9) == 'internal-') {
   687      *
   687      *
   688      * @param  array $tags Array of tags
   688      * @param  array $tags Array of tags
   689      * @throws Zend_Cache_Exception
   689      * @throws Zend_Cache_Exception
   690      * @return void
   690      * @return void
   691      */
   691      */
   692     protected static function _validateTagsArray($tags)
   692     protected function _validateTagsArray($tags)
   693     {
   693     {
   694         if (!is_array($tags)) {
   694         if (!is_array($tags)) {
   695             Zend_Cache::throwException('Invalid tags array : must be an array');
   695             Zend_Cache::throwException('Invalid tags array : must be an array');
   696         }
   696         }
   697         foreach($tags as $tag) {
   697         foreach($tags as $tag) {
   698             self::_validateIdOrTag($tag);
   698             $this->_validateIdOrTag($tag);
   699         }
   699         }
   700         reset($tags);
   700         reset($tags);
   701     }
   701     }
   702 
   702 
   703     /**
   703     /**