[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cache\driver; 15 16 /** 17 * ACM Abstract Memory Class 18 */ 19 abstract class memory extends \phpbb\cache\driver\base 20 { 21 var $key_prefix; 22 23 /** 24 * Set cache path 25 */ 26 function __construct() 27 { 28 global $phpbb_root_path, $dbname, $table_prefix; 29 30 $this->cache_dir = $phpbb_root_path . 'cache/'; 31 $this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_'; 32 33 if (!isset($this->extension) || !extension_loaded($this->extension)) 34 { 35 global $acm_type; 36 37 trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR); 38 } 39 40 if (isset($this->function) && !function_exists($this->function)) 41 { 42 global $acm_type; 43 44 trigger_error("The required function [{$this->function}] is not available for the ACM module $acm_type.", E_USER_ERROR); 45 } 46 } 47 48 /** 49 * {@inheritDoc} 50 */ 51 function load() 52 { 53 // grab the global cache 54 $this->vars = $this->_read('global'); 55 56 if ($this->vars !== false) 57 { 58 return true; 59 } 60 61 return false; 62 } 63 64 /** 65 * {@inheritDoc} 66 */ 67 function save() 68 { 69 if (!$this->is_modified) 70 { 71 return; 72 } 73 74 $this->_write('global', $this->vars, 2592000); 75 76 $this->is_modified = false; 77 } 78 79 /** 80 * {@inheritDoc} 81 */ 82 function tidy() 83 { 84 // cache has auto GC, no need to have any code here :) 85 86 set_config('cache_last_gc', time(), true); 87 } 88 89 /** 90 * {@inheritDoc} 91 */ 92 function get($var_name) 93 { 94 if ($var_name[0] == '_') 95 { 96 if (!$this->_exists($var_name)) 97 { 98 return false; 99 } 100 101 return $this->_read($var_name); 102 } 103 else 104 { 105 return ($this->_exists($var_name)) ? $this->vars[$var_name] : false; 106 } 107 } 108 109 /** 110 * {@inheritDoc} 111 */ 112 function put($var_name, $var, $ttl = 2592000) 113 { 114 if ($var_name[0] == '_') 115 { 116 $this->_write($var_name, $var, $ttl); 117 } 118 else 119 { 120 $this->vars[$var_name] = $var; 121 $this->is_modified = true; 122 } 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 function destroy($var_name, $table = '') 129 { 130 if ($var_name == 'sql' && !empty($table)) 131 { 132 if (!is_array($table)) 133 { 134 $table = array($table); 135 } 136 137 foreach ($table as $table_name) 138 { 139 // gives us the md5s that we want 140 $temp = $this->_read('sql_' . $table_name); 141 142 if ($temp === false) 143 { 144 continue; 145 } 146 147 // delete each query ref 148 foreach ($temp as $md5_id => $void) 149 { 150 $this->_delete('sql_' . $md5_id); 151 } 152 153 // delete the table ref 154 $this->_delete('sql_' . $table_name); 155 } 156 157 return; 158 } 159 160 if (!$this->_exists($var_name)) 161 { 162 return; 163 } 164 165 if ($var_name[0] == '_') 166 { 167 $this->_delete($var_name); 168 } 169 else if (isset($this->vars[$var_name])) 170 { 171 $this->is_modified = true; 172 unset($this->vars[$var_name]); 173 174 // We save here to let the following cache hits succeed 175 $this->save(); 176 } 177 } 178 179 /** 180 * {@inheritDoc} 181 */ 182 function _exists($var_name) 183 { 184 if ($var_name[0] == '_') 185 { 186 return $this->_isset($var_name); 187 } 188 else 189 { 190 if (!sizeof($this->vars)) 191 { 192 $this->load(); 193 } 194 195 return isset($this->vars[$var_name]); 196 } 197 } 198 199 /** 200 * {@inheritDoc} 201 */ 202 function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl) 203 { 204 // Remove extra spaces and tabs 205 $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); 206 $hash = md5($query); 207 208 // determine which tables this query belongs to 209 // Some queries use backticks, namely the get_database_size() query 210 // don't check for conformity, the SQL would error and not reach here. 211 if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER)) 212 { 213 // Bail out if the match fails. 214 return $query_result; 215 } 216 217 $tables = array(); 218 foreach ($regs as $match) 219 { 220 if ($match[0][0] == 'F') 221 { 222 $tables = array_merge($tables, array_map('trim', explode(',', $match[1]))); 223 } 224 else 225 { 226 $tables[] = $match[2]; 227 } 228 } 229 230 foreach ($tables as $table_name) 231 { 232 // Remove backticks 233 $table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name; 234 235 if (($pos = strpos($table_name, ' ')) !== false) 236 { 237 $table_name = substr($table_name, 0, $pos); 238 } 239 240 $temp = $this->_read('sql_' . $table_name); 241 242 if ($temp === false) 243 { 244 $temp = array(); 245 } 246 247 $temp[$hash] = true; 248 249 // This must never expire 250 $this->_write('sql_' . $table_name, $temp, 0); 251 } 252 253 // store them in the right place 254 $query_id = sizeof($this->sql_rowset); 255 $this->sql_rowset[$query_id] = array(); 256 $this->sql_row_pointer[$query_id] = 0; 257 258 while ($row = $db->sql_fetchrow($query_result)) 259 { 260 $this->sql_rowset[$query_id][] = $row; 261 } 262 $db->sql_freeresult($query_result); 263 264 $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); 265 266 return $query_id; 267 } 268 269 /** 270 * Check if a cache var exists 271 * 272 * @access protected 273 * @param string $var Cache key 274 * @return bool True if it exists, otherwise false 275 */ 276 function _isset($var) 277 { 278 // Most caches don't need to check 279 return true; 280 } 281 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |