[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 /** 13 * Memcache Cache Handler 14 */ 15 class memcacheCacheHandler 16 { 17 /** 18 * The memcache server resource 19 */ 20 public $memcache; 21 22 /** 23 * Unique identifier representing this copy of MyBB 24 */ 25 public $unique_id; 26 27 function memcacheCacheHandler($silent=false) 28 { 29 global $mybb; 30 31 if(!function_exists("memcache_connect")) 32 { 33 // Check if our DB engine is loaded 34 if(!extension_loaded("Memcache")) 35 { 36 // Throw our super awesome cache loading error 37 $mybb->trigger_generic_error("memcache_load_error"); 38 die; 39 } 40 } 41 } 42 43 /** 44 * Connect and initialize this handler. 45 * 46 * @return boolean True if successful, false on failure 47 */ 48 function connect() 49 { 50 global $mybb, $error_handler; 51 52 $this->memcache = new Memcache; 53 54 if($mybb->config['memcache']['host']) 55 { 56 $mybb->config['memcache'][0] = $mybb->config['memcache']; 57 unset($mybb->config['memcache']['host']); 58 unset($mybb->config['memcache']['port']); 59 } 60 61 foreach($mybb->config['memcache'] as $memcache) 62 { 63 if(!$memcache['host']) 64 { 65 $message = "Please configure the memcache settings in inc/config.php before attempting to use this cache handler"; 66 $error_handler->trigger($message, MYBB_CACHEHANDLER_LOAD_ERROR); 67 die; 68 } 69 70 if(!isset($memcache['port'])) 71 { 72 $memcache['port'] = "11211"; 73 } 74 75 $this->memcache->addServer($memcache['host'], $memcache['port']); 76 77 if(!$this->memcache) 78 { 79 $message = "Unable to connect to the memcache server on {$memcache['memcache_host']}:{$memcache['memcache_port']}. Are you sure it is running?"; 80 $error_handler->trigger($message, MYBB_CACHEHANDLER_LOAD_ERROR); 81 die; 82 } 83 } 84 85 // Set a unique identifier for all queries in case other forums are using the same memcache server 86 $this->unique_id = md5(MYBB_ROOT); 87 88 return true; 89 } 90 91 /** 92 * Retrieve an item from the cache. 93 * 94 * @param string The name of the cache 95 * @param boolean True if we should do a hard refresh 96 * @return mixed Cache data if successful, false if failure 97 */ 98 99 function fetch($name, $hard_refresh=false) 100 { 101 $data = $this->memcache->get($this->unique_id."_".$name); 102 103 if($data === false) 104 { 105 return false; 106 } 107 else 108 { 109 return $data; 110 } 111 } 112 113 /** 114 * Write an item to the cache. 115 * 116 * @param string The name of the cache 117 * @param mixed The data to write to the cache item 118 * @return boolean True on success, false on failure 119 */ 120 function put($name, $contents) 121 { 122 return $this->memcache->set($this->unique_id."_".$name, $contents); 123 } 124 125 /** 126 * Delete a cache 127 * 128 * @param string The name of the cache 129 * @return boolean True on success, false on failure 130 */ 131 function delete($name) 132 { 133 return $this->memcache->delete($this->unique_id."_".$name); 134 } 135 136 /** 137 * Disconnect from the cache 138 */ 139 function disconnect() 140 { 141 @$this->memcache->close(); 142 } 143 144 function size_of($name) 145 { 146 global $lang; 147 148 return $lang->na; 149 } 150 } 151 152 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |