[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/inc/cachehandlers/ -> apcu.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2020 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  /**
  12   * APCu Cache Handler
  13   */
  14  class apcuCacheHandler implements CacheHandlerInterface
  15  {
  16      /**
  17       * Unique identifier representing this copy of MyBB
  18       *
  19       * @var string
  20       */
  21      public $unique_id;
  22  
  23  	function __construct()
  24      {
  25          global $mybb;
  26  
  27          if(!function_exists('apcu_fetch'))
  28          {
  29              // Check if the APCu extension is loaded
  30              if(!extension_loaded('apcu'))
  31              {
  32                  $mybb->trigger_generic_error('apcu_load_error');
  33                  die;
  34              }
  35          }
  36      }
  37  
  38      /**
  39       * Connect and initialize this handler.
  40       *
  41       * @return boolean True if successful, false on failure
  42       */
  43  	function connect()
  44      {
  45          // Set a unique identifier for all queries in case other forums on this server also use this cache handler
  46          $this->unique_id = md5(MYBB_ROOT);
  47  
  48          return true;
  49      }
  50  
  51      /**
  52       * Connect and initialize this handler.
  53       *
  54       * @param string $name
  55       * @return mixed The cache content if successful, false on failure
  56       */
  57  	function fetch($name)
  58      {
  59          if(apcu_exists("{$this->unique_id}_{$name}"))
  60          {
  61              return apcu_fetch("{$this->unique_id}_{$name}");
  62          }
  63  
  64          return false;
  65      }
  66  
  67      /**
  68       * Write an item to the cache.
  69       *
  70       * @param string $name The name of the cache
  71       * @param mixed $contents The data to write to the cache item
  72       * @return boolean True on success, false on failure
  73       */
  74  	function put($name, $contents)
  75      {
  76          return apcu_store("{$this->unique_id}_{$name}", $contents);
  77      }
  78  
  79      /**
  80       * Delete a cache
  81       *
  82       * @param string $name The name of the cache
  83       * @return boolean True on success, false on failure
  84       */
  85  	function delete($name)
  86      {
  87          return apcu_delete("{$this->unique_id}_{$name}");
  88      }
  89  
  90      /**
  91       * Disconnect from the cache
  92       *
  93       * @return bool
  94       */
  95  	function disconnect()
  96      {
  97          return true;
  98      }
  99  
 100      /**
 101       * @param string $name
 102       *
 103       * @return string
 104       */
 105  	function size_of($name='')
 106      {
 107          if(empty($name))
 108          {
 109              // get total size of cache, using an APCUIterator
 110              $iterator = new APCUIterator("/^{$this->unique_id}_.*/");
 111              return $iterator->getTotalSize();
 112          }
 113          
 114          global $lang;
 115  
 116          $info = apcu_cache_info();
 117  
 118          if(empty($info['cache_list']))
 119          {
 120              return $lang->na;
 121          }
 122  
 123          $actual_name = "{$this->unique_id}_{$name}";
 124  
 125          foreach($info['cache_list'] as $entry)
 126          {
 127              if(isset($entry['info']) && $entry['info'] === $actual_name && isset($entry['mem_size']))
 128              {
 129                  return $entry['mem_size'];
 130              }
 131          }
 132  
 133          return $lang->na;
 134      }
 135  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref