MediaWiki  1.23.1
ObjectCache.php
Go to the documentation of this file.
1 <?php
29 class ObjectCache {
30  static $instances = array();
31 
39  static function getInstance( $id ) {
40  if ( isset( self::$instances[$id] ) ) {
41  return self::$instances[$id];
42  }
43 
44  $object = self::newFromId( $id );
45  self::$instances[$id] = $object;
46  return $object;
47  }
48 
52  static function clear() {
53  self::$instances = array();
54  }
55 
64  static function newFromId( $id ) {
65  global $wgObjectCaches;
66 
67  if ( !isset( $wgObjectCaches[$id] ) ) {
68  throw new MWException( "Invalid object cache type \"$id\" requested. " .
69  "It is not present in \$wgObjectCaches." );
70  }
71 
72  return self::newFromParams( $wgObjectCaches[$id] );
73  }
74 
83  static function newFromParams( $params ) {
84  if ( isset( $params['factory'] ) ) {
85  return call_user_func( $params['factory'], $params );
86  } elseif ( isset( $params['class'] ) ) {
87  $class = $params['class'];
88  return new $class( $params );
89  } else {
90  throw new MWException( "The definition of cache type \"" . print_r( $params, true ) . "\" lacks both " .
91  "factory and class parameters." );
92  }
93  }
94 
107  static function newAnything( $params ) {
108  global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
109  $candidates = array( $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType );
110  foreach ( $candidates as $candidate ) {
111  if ( $candidate !== CACHE_NONE && $candidate !== CACHE_ANYTHING ) {
112  return self::getInstance( $candidate );
113  }
114  }
115  return self::getInstance( CACHE_DB );
116  }
117 
125  static function newAccelerator( $params ) {
126  if ( function_exists( 'apc_fetch' ) ) {
127  $id = 'apc';
128  } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
129  $id = 'xcache';
130  } elseif ( function_exists( 'wincache_ucache_get' ) ) {
131  $id = 'wincache';
132  } else {
133  throw new MWException( "CACHE_ACCEL requested but no suitable object " .
134  "cache is present. You may want to install APC." );
135  }
136  return self::newFromId( $id );
137  }
138 
150  static function newMemcached( $params ) {
151  return new MemcachedPhpBagOStuff( $params );
152  }
153 }
ObjectCache\clear
static clear()
Clear all the cached instances.
Definition: ObjectCache.php:52
ObjectCache\newFromId
static newFromId( $id)
Create a new cache object of the specified type.
Definition: ObjectCache.php:64
ObjectCache
Functions to get cache objects.
Definition: ObjectCache.php:29
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
CACHE_NONE
const CACHE_NONE
Definition: Defines.php:112
MemcachedPhpBagOStuff
A wrapper class for the pure-PHP memcached client, exposing a BagOStuff interface.
Definition: MemcachedPhpBagOStuff.php:29
$params
$params
Definition: styleTest.css.php:40
ObjectCache\newAnything
static newAnything( $params)
Factory function referenced from DefaultSettings.php for CACHE_ANYTHING.
Definition: ObjectCache.php:107
MWException
MediaWiki exception.
Definition: MWException.php:26
ObjectCache\newMemcached
static newMemcached( $params)
Factory function that creates a memcached client object.
Definition: ObjectCache.php:150
ObjectCache\$instances
static $instances
Definition: ObjectCache.php:30
ObjectCache\getInstance
static getInstance( $id)
Get a cached instance of the specified type of cache object.
Definition: ObjectCache.php:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
CACHE_ANYTHING
const CACHE_ANYTHING
Definition: Defines.php:111
ObjectCache\newAccelerator
static newAccelerator( $params)
Factory function referenced from DefaultSettings.php for CACHE_ACCEL.
Definition: ObjectCache.php:125
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
Definition: GlobalFunctions.php:2685
$wgMainCacheType
CACHE_MEMCACHED $wgMainCacheType
Definition: memcached.txt:63
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ObjectCache\newFromParams
static newFromParams( $params)
Create a new cache object from parameters.
Definition: ObjectCache.php:83
CACHE_DB
const CACHE_DB
Definition: Defines.php:113