| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: apc.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 * APC cache storage handler 20 * 21 * @package Joomla.Framework 22 * @subpackage Cache 23 * @since 1.5 24 */ 25 class JCacheStorageApc extends JCacheStorage 26 { 27 /** 28 * Constructor 29 * 30 * @access protected 31 * @param array $options optional parameters 32 */ 33 function __construct( $options = array() ) 34 { 35 parent::__construct($options); 36 37 $config =& JFactory::getConfig(); 38 $this->_hash = $config->getValue('config.secret'); 39 } 40 41 /** 42 * Get cached data from APC by id and group 43 * 44 * @access public 45 * @param string $id The cache data id 46 * @param string $group The cache data group 47 * @param boolean $checkTime True to verify cache time expiration threshold 48 * @return mixed Boolean false on failure or a cached data string 49 * @since 1.5 50 */ 51 function get($id, $group, $checkTime) 52 { 53 $cache_id = $this->_getCacheId($id, $group); 54 $this->_setExpire($cache_id); 55 return apc_fetch($cache_id); 56 } 57 58 /** 59 * Store the data to APC by id and group 60 * 61 * @access public 62 * @param string $id The cache data id 63 * @param string $group The cache data group 64 * @param string $data The data to store in cache 65 * @return boolean True on success, false otherwise 66 * @since 1.5 67 */ 68 function store($id, $group, $data) 69 { 70 $cache_id = $this->_getCacheId($id, $group); 71 apc_store($cache_id.'_expire', time()); 72 return apc_store($cache_id, $data, $this->_lifetime); 73 } 74 75 /** 76 * Remove a cached data entry by id and group 77 * 78 * @access public 79 * @param string $id The cache data id 80 * @param string $group The cache data group 81 * @return boolean True on success, false otherwise 82 * @since 1.5 83 */ 84 function remove($id, $group) 85 { 86 $cache_id = $this->_getCacheId($id, $group); 87 apc_delete($cache_id.'_expire'); 88 return apc_delete($cache_id); 89 } 90 91 /** 92 * Clean cache for a group given a mode. 93 * 94 * group mode : cleans all cache in the group 95 * notgroup mode : cleans all cache not in the group 96 * 97 * @access public 98 * @param string $group The cache data group 99 * @param string $mode The mode for cleaning cache [group|notgroup] 100 * @return boolean True on success, false otherwise 101 * @since 1.5 102 */ 103 function clean($group, $mode) 104 { 105 return true; 106 } 107 108 /** 109 * Test to see if the cache storage is available. 110 * 111 * @static 112 * @access public 113 * @return boolean True on success, false otherwise. 114 */ 115 function test() 116 { 117 return extension_loaded('apc'); 118 } 119 120 /** 121 * Set expire time on each call since memcache sets it on cache creation. 122 * 123 * @access private 124 * 125 * @param string $key Cache key to expire. 126 * @param integer $lifetime Lifetime of the data in seconds. 127 */ 128 function _setExpire($key) 129 { 130 $lifetime = $this->_lifetime; 131 $expire = apc_fetch($key.'_expire'); 132 133 // set prune period 134 if ($expire + $lifetime < time()) { 135 apc_delete($key); 136 apc_delete($key.'_expire'); 137 } else { 138 apc_store($key.'_expire', time()); 139 } 140 } 141 142 /** 143 * Get a cache_id string from an id/group pair 144 * 145 * @access private 146 * @param string $id The cache data id 147 * @param string $group The cache data group 148 * @return string The cache_id string 149 * @since 1.5 150 */ 151 function _getCacheId($id, $group) 152 { 153 $name = md5($this->_application.'-'.$id.'-'.$this->_hash.'-'.$this->_language); 154 return 'cache_'.$group.'-'.$name; 155 } 156 }
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 |