| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: memcache.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla.Framework 5 * @subpackage Cache 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 /** 19 * Memcache cache storage handler 20 * 21 * @package Joomla.Framework 22 * @subpackage Cache 23 * @since 1.5 24 */ 25 class JCacheStorageMemcache extends JCacheStorage 26 { 27 /** 28 * Resource for the current memcached connection. 29 * @var resource 30 */ 31 var $_db; 32 33 /** 34 * Use compression? 35 * @var int 36 */ 37 var $_compress = null; 38 39 /** 40 * Use persistent connections 41 * @var boolean 42 */ 43 var $_persistent = false; 44 45 /** 46 * Constructor 47 * 48 * @access protected 49 * @param array $options optional parameters 50 */ 51 function __construct( $options = array() ) 52 { 53 if (!$this->test()) { 54 return JError::raiseError(404, "The memcache extension is not available"); 55 } 56 parent::__construct($options); 57 58 $params =& JCacheStorageMemcache::getConfig(); 59 $this->_compress = (isset($params['compression'])) ? $params['compression'] : 0; 60 $this->_db =& JCacheStorageMemcache::getConnection(); 61 62 // Get the site hash 63 $this->_hash = $params['hash']; 64 } 65 66 /** 67 * return memcache connection object 68 * 69 * @static 70 * @access private 71 * @return object memcache connection object 72 */ 73 function &getConnection() { 74 static $db = null; 75 if(is_null($db)) { 76 $params =& JCacheStorageMemcache::getConfig(); 77 $persistent = (isset($params['persistent'])) ? $params['persistent'] : false; 78 // This will be an array of loveliness 79 $servers = (isset($params['servers'])) ? $params['servers'] : array(); 80 81 // Create the memcache connection 82 $db = new Memcache; 83 foreach($servers AS $server) { 84 $db->addServer($server['host'], $server['port'], $persistent); 85 } 86 } 87 return $db; 88 } 89 90 /** 91 * Return memcache related configuration 92 * 93 * @static 94 * @access private 95 * @return array options 96 */ 97 function &getConfig() { 98 static $params = null; 99 if(is_null($params)) { 100 $config =& JFactory::getConfig(); 101 $params = $config->getValue('config.memcache_settings'); 102 if (!is_array($params)) { 103 $params = unserialize(stripslashes($params)); 104 } 105 106 if (!$params) { 107 $params = array(); 108 } 109 $params['hash'] = $config->getValue('config.secret'); 110 } 111 return $params; 112 } 113 114 /** 115 * Get cached data from memcache by id and group 116 * 117 * @access public 118 * @param string $id The cache data id 119 * @param string $group The cache data group 120 * @param boolean $checkTime True to verify cache time expiration threshold 121 * @return mixed Boolean false on failure or a cached data string 122 * @since 1.5 123 */ 124 function get($id, $group, $checkTime) 125 { 126 $cache_id = $this->_getCacheId($id, $group); 127 return $this->_db->get($cache_id); 128 } 129 130 /** 131 * Store the data to memcache by id and group 132 * 133 * @access public 134 * @param string $id The cache data id 135 * @param string $group The cache data group 136 * @param string $data The data to store in cache 137 * @return boolean True on success, false otherwise 138 * @since 1.5 139 */ 140 function store($id, $group, $data) 141 { 142 $cache_id = $this->_getCacheId($id, $group); 143 return $this->_db->set($cache_id, $data, $this->_compress, $this->_lifetime); 144 } 145 146 /** 147 * Remove a cached data entry by id and group 148 * 149 * @access public 150 * @param string $id The cache data id 151 * @param string $group The cache data group 152 * @return boolean True on success, false otherwise 153 * @since 1.5 154 */ 155 function remove($id, $group) 156 { 157 $cache_id = $this->_getCacheId($id, $group); 158 return $this->_db->delete($cache_id); 159 } 160 161 /** 162 * Clean cache for a group given a mode. 163 * 164 * group mode : cleans all cache in the group 165 * notgroup mode : cleans all cache not in the group 166 * 167 * @access public 168 * @param string $group The cache data group 169 * @param string $mode The mode for cleaning cache [group|notgroup] 170 * @return boolean True on success, false otherwise 171 * @since 1.5 172 */ 173 function clean($group, $mode) 174 { 175 return true; 176 } 177 178 /** 179 * Garbage collect expired cache data 180 * 181 * @access public 182 * @return boolean True on success, false otherwise. 183 */ 184 function gc() 185 { 186 return true; 187 } 188 189 /** 190 * Test to see if the cache storage is available. 191 * 192 * @static 193 * @access public 194 * @return boolean True on success, false otherwise. 195 */ 196 function test() 197 { 198 return (extension_loaded('memcache') && class_exists('Memcache')); 199 } 200 201 /** 202 * Get a cache_id string from an id/group pair 203 * 204 * @access private 205 * @param string $id The cache data id 206 * @param string $group The cache data group 207 * @return string The cache_id string 208 * @since 1.5 209 */ 210 function _getCacheId($id, $group) 211 { 212 $name = md5($this->_application.'-'.$id.'-'.$this->_hash.'-'.$this->_language); 213 return 'cache_'.$group.'-'.$name; 214 } 215 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |