Overview

Packages

  • Cache

Classes

  • Horde_Cache
  • Horde_Cache_Exception
  • Horde_Cache_Storage_Apc
  • Horde_Cache_Storage_Base
  • Horde_Cache_Storage_Eaccelerator
  • Horde_Cache_Storage_File
  • Horde_Cache_Storage_Memcache
  • Horde_Cache_Storage_Mock
  • Horde_Cache_Storage_Null
  • Horde_Cache_Storage_Session
  • Horde_Cache_Storage_Sql
  • Horde_Cache_Storage_Stack
  • Horde_Cache_Storage_Xcache
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This class provides cache storage in eAccelerator (version 0.9.5+).
  4:  *
  5:  * Copyright 2006-2007 Duck <duck@obala.net>
  6:  *
  7:  * See the enclosed file COPYING for license information (LGPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  9:  *
 10:  * @author   Duck <duck@obala.net>
 11:  * @category Horde
 12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 13:  * @package  Cache
 14:  */
 15: class Horde_Cache_Storage_Eaccelerator extends Horde_Cache_Storage_Base
 16: {
 17:     /**
 18:      * Constructor.
 19:      *
 20:      * @param array $params  Optional parameters:
 21:      * <pre>
 22:      * 'prefix' - (string) The prefix to use for the cache keys.
 23:      *            DEFAULT: ''
 24:      * </pre>
 25:      *
 26:      * @throws Horde_Cache_Exception
 27:      */
 28:     public function __construct(array $params = array())
 29:     {
 30:         if (!function_exists('eaccelerator_gc')) {
 31:             throw new Horde_Cache_Exception('eAccelerator must be compiled with support for shared memory to use as caching backend.');
 32:         }
 33: 
 34:         parent::__construct(array_merge(array(
 35:             'prefix' => '',
 36:         ), $params));
 37:     }
 38: 
 39:     /**
 40:      */
 41:     public function get($key, $lifetime = 0)
 42:     {
 43:         $key = $this->_params['prefix'] . $key;
 44:         $this->_setExpire($key, $lifetime);
 45:         return eaccelerator_get($key);
 46:     }
 47: 
 48:     /**
 49:      */
 50:     public function set($key, $data, $lifetime = 0)
 51:     {
 52:         $key = $this->_params['prefix'] . $key;
 53:         if (eaccelerator_put($key . '_expire', time(), $lifetime)) {
 54:             eaccelerator_put($key, $data, $lifetime);
 55:         }
 56:     }
 57: 
 58:     /**
 59:      */
 60:     public function exists($key, $lifetime = 0)
 61:     {
 62:         $key = $this->_params['prefix'] . $key;
 63:         $this->_setExpire($key, $lifetime);
 64:         return eaccelerator_get($key) !== false;
 65:     }
 66: 
 67:     /**
 68:      */
 69:     public function expire($key)
 70:     {
 71:         $key = $this->_params['prefix'] . $key;
 72:         eaccelerator_rm($key . '_expire');
 73:         return eaccelerator_rm($key);
 74:     }
 75: 
 76:     /**
 77:      */
 78:     public function clear()
 79:     {
 80:         eaccelerator_clear();
 81:     }
 82: 
 83:     /**
 84:      * Set expire time on each call since eAccelerator sets it on
 85:      * cache creation.
 86:      *
 87:      * @param string $key        Cache key to expire.
 88:      * @param integer $lifetime  Lifetime of the data in seconds.
 89:      */
 90:     protected function _setExpire($key, $lifetime)
 91:     {
 92:         if ($lifetime == 0) {
 93:             // Don't expire.
 94:             return;
 95:         }
 96: 
 97:         $key = $this->_params['prefix'] . $key;
 98:         $expire = eaccelerator_get($key . '_expire');
 99: 
100:         // Set prune period.
101:         if ($expire + $lifetime < time()) {
102:             // Expired
103:             eaccelerator_rm($key);
104:             eaccelerator_rm($key . '_expire');
105:         }
106:     }
107: 
108: }
109: 
API documentation generated by ApiGen