Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 $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 $data = $this->_read('global');
055
056 if ($data !== false)
057 {
058 $this->vars = $data;
059 return true;
060 }
061
062 return false;
063 }
064
065 /**
066 * {@inheritDoc}
067 */
068 function save()
069 {
070 if (!$this->is_modified)
071 {
072 return;
073 }
074
075 $this->_write('global', $this->vars, 2592000);
076
077 $this->is_modified = false;
078 }
079
080 /**
081 * {@inheritDoc}
082 */
083 function tidy()
084 {
085 global $config;
086
087 // cache has auto GC, no need to have any code here :)
088 $config->set('cache_last_gc', time(), false);
089 }
090
091 /**
092 * {@inheritDoc}
093 */
094 function get($var_name)
095 {
096 if ($var_name[0] == '_')
097 {
098 if (!$this->_exists($var_name))
099 {
100 return false;
101 }
102
103 return $this->_read($var_name);
104 }
105 else
106 {
107 return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
108 }
109 }
110
111 /**
112 * {@inheritDoc}
113 */
114 function put($var_name, $var, $ttl = 2592000)
115 {
116 if ($var_name[0] == '_')
117 {
118 $this->_write($var_name, $var, $ttl);
119 }
120 else
121 {
122 $this->vars[$var_name] = $var;
123 $this->is_modified = true;
124 }
125 }
126
127 /**
128 * {@inheritDoc}
129 */
130 function destroy($var_name, $table = '')
131 {
132 if ($var_name == 'sql' && !empty($table))
133 {
134 if (!is_array($table))
135 {
136 $table = array($table);
137 }
138
139 foreach ($table as $table_name)
140 {
141 // gives us the md5s that we want
142 $temp = $this->_read('sql_' . $table_name);
143
144 if ($temp === false)
145 {
146 continue;
147 }
148
149 // delete each query ref
150 foreach ($temp as $md5_id => $void)
151 {
152 $this->_delete('sql_' . $md5_id);
153 }
154
155 // delete the table ref
156 $this->_delete('sql_' . $table_name);
157 }
158
159 return;
160 }
161
162 if (!$this->_exists($var_name))
163 {
164 return;
165 }
166
167 if ($var_name[0] == '_')
168 {
169 $this->_delete($var_name);
170 }
171 else if (isset($this->vars[$var_name]))
172 {
173 $this->is_modified = true;
174 unset($this->vars[$var_name]);
175
176 // We save here to let the following cache hits succeed
177 $this->save();
178 }
179 }
180
181 /**
182 * {@inheritDoc}
183 */
184 function _exists($var_name)
185 {
186 if ($var_name[0] == '_')
187 {
188 return $this->_isset($var_name);
189 }
190 else
191 {
192 if (!count($this->vars))
193 {
194 $this->load();
195 }
196
197 return isset($this->vars[$var_name]);
198 }
199 }
200
201 /**
202 * {@inheritDoc}
203 */
204 function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl)
205 {
206 // Remove extra spaces and tabs
207 $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
208 $query_id = md5($query);
209
210 // determine which tables this query belongs to
211 // Some queries use backticks, namely the get_database_size() query
212 // don't check for conformity, the SQL would error and not reach here.
213 if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER))
214 {
215 // Bail out if the match fails.
216 return $query_result;
217 }
218
219 $tables = array();
220 foreach ($regs as $match)
221 {
222 if ($match[0][0] == 'F')
223 {
224 $tables = array_merge($tables, array_map('trim', explode(',', $match[1])));
225 }
226 else
227 {
228 $tables[] = $match[2];
229 }
230 }
231
232 foreach ($tables as $table_name)
233 {
234 // Remove backticks
235 $table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name;
236
237 if (($pos = strpos($table_name, ' ')) !== false)
238 {
239 $table_name = substr($table_name, 0, $pos);
240 }
241
242 $temp = $this->_read('sql_' . $table_name);
243
244 if ($temp === false)
245 {
246 $temp = array();
247 }
248
249 $temp[$query_id] = true;
250
251 // This must never expire
252 $this->_write('sql_' . $table_name, $temp, 0);
253 }
254
255 // store them in the right place
256 $this->sql_rowset[$query_id] = array();
257 $this->sql_row_pointer[$query_id] = 0;
258
259 while ($row = $db->sql_fetchrow($query_result))
260 {
261 $this->sql_rowset[$query_id][] = $row;
262 }
263 $db->sql_freeresult($query_result);
264
265 $this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl);
266
267 return $query_id;
268 }
269
270 /**
271 * Check if a cache var exists
272 *
273 * @access protected
274 * @param string $var Cache key
275 * @return bool True if it exists, otherwise false
276 */
277 function _isset($var)
278 {
279 // Most caches don't need to check
280 return true;
281 }
282 }
283