PageRenderTime 67ms CodeModel.GetById 61ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/zend/Zend/Cache/Backend/ZendServer/ShMem.php

http://zoop.googlecode.com/
PHP | 100 lines | 35 code | 9 blank | 56 comment | 2 complexity | acbf64bcad586c310aaf5f07061ef101 MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 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.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Cache
 17 * @subpackage Zend_Cache_Backend
 18 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: ShMem.php 20096 2010-01-06 02:05:09Z bkarwin $
 21 */
 22
 23
 24/** @see Zend_Cache_Backend_Interface */
 25require_once 'Zend/Cache/Backend/Interface.php';
 26
 27/** @see Zend_Cache_Backend_ZendServer */
 28require_once 'Zend/Cache/Backend/ZendServer.php';
 29
 30
 31/**
 32 * @package    Zend_Cache
 33 * @subpackage Zend_Cache_Backend
 34 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 35 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 36 */
 37class Zend_Cache_Backend_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
 38{
 39    /**
 40     * Constructor
 41     *
 42     * @param  array $options associative array of options
 43     * @throws Zend_Cache_Exception
 44     */
 45    public function __construct(array $options = array())
 46    {
 47        if (!function_exists('zend_shm_cache_store')) {
 48            Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
 49        }
 50        parent::__construct($options);
 51    }
 52
 53    /**
 54     * Store data
 55     *
 56     * @param mixed  $data        Object to store
 57     * @param string $id          Cache id
 58     * @param int    $timeToLive  Time to live in seconds
 59     *
 60     */
 61    protected function _store($data, $id, $timeToLive)
 62    {
 63        if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id,
 64                                  $data,
 65                                  $timeToLive) === false) {
 66            $this->_log('Store operation failed.');
 67            return false;
 68        }
 69        return true;
 70    }
 71
 72    /**
 73     * Fetch data
 74     *
 75     * @param string $id          Cache id
 76     */
 77    protected function _fetch($id)
 78    {
 79        return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
 80    }
 81
 82    /**
 83     * Unset data
 84     *
 85     * @param string $id          Cache id
 86     * @return boolean true if no problem
 87     */
 88    protected function _unset($id)
 89    {
 90        return zend_shm_cache_delete($this->_options['namespace'] . '::' . $id);
 91    }
 92
 93    /**
 94     * Clear cache
 95     */
 96    protected function _clear()
 97    {
 98        zend_shm_cache_clear($this->_options['namespace']);
 99    }
100}