Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
memory.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\cache\driver;
015
016 /**
017 * ACM Abstract Memory Class
018 */
019 abstract class memory extends \phpbb\cache\driver\base
020 {
021 var $key_prefix;
022
023 /**
024 * Set cache path
025 */
026 function __construct()
027 {
028 global $phpbb_root_path, $dbname, $table_prefix, $phpbb_container;
029
030 $this->cache_dir = $phpbb_container->getParameter('core.cache_dir');
031 $this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_';
032
033 if (!isset($this->extension) || !extension_loaded($this->extension))
034 {
035 global $acm_type;
036
037 trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR);
038 }
039
040 if (isset($this->function) && !function_exists($this->function))
041 {
042 global $acm_type;
043
044 trigger_error("The required function [{$this->function}] is not available for the ACM module $acm_type.", E_USER_ERROR);
045 }
046 }
047
048 /**
049 * {@inheritDoc}
050 */
051 function load()
052 {
053 // grab the global cache
054 $this->vars = $this->_read('global');
055
056 if ($this->vars !== false)
057 {
058 return true;
059 }
060
061 return false;
062 }
063
064 /**
065 * {@inheritDoc}
066 */
067 function save()
068 {
069 if (!$this->is_modified)
070 {
071 return;
072 }
073
074 $this->_write('global', $this->vars, 2592000);
075
076 $this->is_modified = false;
077 }
078
079 /**
080 * {@inheritDoc}
081 */
082 function tidy()
083 {
084 global $config;
085
086 // cache has auto GC, no need to have any code here :)
087 $config->set('cache_last_gc', time(), false);
088 }
089
090 /**
091 * {@inheritDoc}
092 */
093 function get($var_name)
094 {
095 if ($var_name[0] == '_')
096 {
097 if (!$this->_exists($var_name))
098 {
099 return false;
100 }
101
102 return $this->_read($var_name);
103 }
104 else
105 {
106 return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
107 }
108 }
109
110 /**
111 * {@inheritDoc}
112 */
113 function put($var_name, $var, $ttl = 2592000)
114 {
115 if ($var_name[0] == '_')
116 {
117 $this->_write($var_name, $var, $ttl);
118 }
119 else
120 {
121 $this->vars[$var_name] = $var;
122 $this->is_modified = true;
123 }
124 }
125
126 /**
127 * {@inheritDoc}
128 */
129 function destroy($var_name, $table = '')
130 {
131 if ($var_name == 'sql' && !empty($table))
132 {
133 if (!is_array($table))
134 {
135 $table = array($table);
136 }
137
138 foreach ($table as $table_name)
139 {
140 // gives us the md5s that we want
141 $temp = $this->_read('sql_' . $table_name);
142
143 if ($temp === false)
144 {
145 continue;
146 }
147
148 // delete each query ref
149 foreach ($temp as $md5_id => $void)
150 {
151 $this->_delete('sql_' . $md5_id);
152 }
153
154 // delete the table ref
155 $this->_delete('sql_' . $table_name);
156 }
157
158 return;
159 }
160
161 if (!$this->_exists($var_name))
162 {
163 return;
164 }
165
166 if ($var_name[0] == '_')
167 {
168 $this->_delete($var_name);
169 }
170 else if (isset($this->vars[$var_name]))
171 {
172 $this->is_modified = true;
173 unset($this->vars[$var_name]);
174
175 // We save here to let the following cache hits succeed
176 $this->save();
177 }
178 }
179
180 /**
181 * {@inheritDoc}
182 */
183 function _exists($var_name)
184 {
185 if ($var_name[0] == '_')
186 {
187 return $this->_isset($var_name);
188 }
189 else
190 {
191 if (!sizeof($this->vars))
192 {
193 $this->load();
194 }
195
196 return isset($this->vars[$var_name]);
197 }
198 }
199
200 /**
201 * {@inheritDoc}
202 */
203 function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl)
204 {
205 // Remove extra spaces and tabs
206 $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
207 $query_id = md5($query);
208
209 // determine which tables this query belongs to
210 // Some queries use backticks, namely the get_database_size() query
211 // don't check for conformity, the SQL would error and not reach here.
212 if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER))
213 {
214 // Bail out if the match fails.
215 return $query_result;
216 }
217
218 $tables = array();
219 foreach ($regs as $match)
220 {
221 if ($match[0][0] == 'F')
222 {
223 $tables = array_merge($tables, array_map('trim', explode(',', $match[1])));
224 }
225 else
226 {
227 $tables[] = $match[2];
228 }
229 }
230
231 foreach ($tables as $table_name)
232 {
233 // Remove backticks
234 $table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name;
235
236 if (($pos = strpos($table_name, ' ')) !== false)
237 {
238 $table_name = substr($table_name, 0, $pos);
239 }
240
241 $temp = $this->_read('sql_' . $table_name);
242
243 if ($temp === false)
244 {
245 $temp = array();
246 }
247
248 $temp[$query_id] = true;
249
250 // This must never expire
251 $this->_write('sql_' . $table_name, $temp, 0);
252 }
253
254 // store them in the right place
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_' . $query_id, $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 }
282