[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/objectcache/ -> XCacheBagOStuff.php (source)

   1  <?php
   2  /**
   3   * Object caching using XCache.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Cache
  22   */
  23  
  24  /**
  25   * Wrapper for XCache object caching functions; identical interface
  26   * to the APC wrapper
  27   *
  28   * @ingroup Cache
  29   */
  30  class XCacheBagOStuff extends BagOStuff {
  31      /**
  32       * Get a value from the XCache object cache
  33       *
  34       * @param string $key Cache key
  35       * @param mixed $casToken Cas token
  36       * @return mixed
  37       */
  38  	public function get( $key, &$casToken = null ) {
  39          $val = xcache_get( $key );
  40  
  41          if ( is_string( $val ) ) {
  42              if ( $this->isInteger( $val ) ) {
  43                  $val = intval( $val );
  44              } else {
  45                  $val = unserialize( $val );
  46              }
  47          } elseif ( is_null( $val ) ) {
  48              return false;
  49          }
  50  
  51          return $val;
  52      }
  53  
  54      /**
  55       * Store a value in the XCache object cache
  56       *
  57       * @param string $key Cache key
  58       * @param mixed $value Object to store
  59       * @param int $expire Expiration time
  60       * @return bool
  61       */
  62  	public function set( $key, $value, $expire = 0 ) {
  63          if ( !$this->isInteger( $value ) ) {
  64              $value = serialize( $value );
  65          }
  66  
  67          xcache_set( $key, $value, $expire );
  68          return true;
  69      }
  70  
  71      /**
  72       * @param mixed $casToken
  73       * @param string $key
  74       * @param mixed $value
  75       * @param int $exptime
  76       * @return bool
  77       */
  78  	public function cas( $casToken, $key, $value, $exptime = 0 ) {
  79          // Can't find any documentation on xcache cas
  80          throw new MWException( "CAS is not implemented in " . __CLASS__ );
  81      }
  82  
  83      /**
  84       * Remove a value from the XCache object cache
  85       *
  86       * @param string $key Cache key
  87       * @param int $time Not used in this implementation
  88       * @return bool
  89       */
  90  	public function delete( $key, $time = 0 ) {
  91          xcache_unset( $key );
  92          return true;
  93      }
  94  
  95      /**
  96       * Merge an item.
  97       * XCache does not seem to support any way of performing CAS - this however will
  98       * provide a way to perform CAS-like functionality.
  99       *
 100       * @param string $key
 101       * @param Closure $callback Callback method to be executed
 102       * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
 103       * @param int $attempts The amount of times to attempt a merge in case of failure
 104       * @return bool Success
 105       */
 106  	public function merge( $key, Closure $callback, $exptime = 0, $attempts = 10 ) {
 107          return $this->mergeViaLock( $key, $callback, $exptime, $attempts );
 108      }
 109  
 110  	public function incr( $key, $value = 1 ) {
 111          return xcache_inc( $key, $value );
 112      }
 113  
 114  	public function decr( $key, $value = 1 ) {
 115          return xcache_dec( $key, $value );
 116      }
 117  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1