Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

memory.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.11 KiB


 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;
 029   
 030          $this->cache_dir    = $phpbb_root_path . 'cache/';
 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          // cache has auto GC, no need to have any code here :)
 085   
 086          set_config('cache_last_gc', time(), true);
 087      }
 088   
 089      /**
 090      * {@inheritDoc}
 091      */
 092      function get($var_name)
 093      {
 094          if ($var_name[0] == '_')
 095          {
 096              if (!$this->_exists($var_name))
 097              {
 098                  return false;
 099              }
 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  }
 282