File indexing completed on 2025-01-19 05:20:56

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Cache
0017  * @subpackage Zend_Cache_Backend
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 
0024 /** @see Zend_Cache_Backend_Interface */
0025 // require_once 'Zend/Cache/Backend/Interface.php';
0026 
0027 /** @see Zend_Cache_Backend_ZendServer */
0028 // require_once 'Zend/Cache/Backend/ZendServer.php';
0029 
0030 
0031 /**
0032  * @package    Zend_Cache
0033  * @subpackage Zend_Cache_Backend
0034  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0035  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0036  */
0037 class Zend_Cache_Backend_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
0038 {
0039     /**
0040      * Constructor
0041      *
0042      * @param  array $options associative array of options
0043      * @throws Zend_Cache_Exception
0044      */
0045     public function __construct(array $options = array())
0046     {
0047         if (!function_exists('zend_shm_cache_store')) {
0048             Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
0049         }
0050         parent::__construct($options);
0051     }
0052 
0053     /**
0054      * Store data
0055      *
0056      * @param mixed  $data       Object to store
0057      * @param string $id         Cache id
0058      * @param int    $timeToLive Time to live in seconds
0059      * @return bool
0060      */
0061     protected function _store($data, $id, $timeToLive)
0062     {
0063         if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id,
0064                                   $data,
0065                                   $timeToLive) === false) {
0066             $this->_log('Store operation failed.');
0067             return false;
0068         }
0069         return true;
0070     }
0071 
0072     /**
0073      * Fetch data
0074      *
0075      * @param string $id Cache id
0076      * @return mixed|null
0077      */
0078     protected function _fetch($id)
0079     {
0080         return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
0081     }
0082 
0083     /**
0084      * Unset data
0085      *
0086      * @param string $id          Cache id
0087      * @return boolean true if no problem
0088      */
0089     protected function _unset($id)
0090     {
0091         return zend_shm_cache_delete($this->_options['namespace'] . '::' . $id);
0092     }
0093 
0094     /**
0095      * Clear cache
0096      */
0097     protected function _clear()
0098     {
0099         zend_shm_cache_clear($this->_options['namespace']);
0100     }
0101 }