MediaWiki
REL1_22
|
00001 <?php 00029 class ObjectCache { 00030 static $instances = array(); 00031 00039 static function getInstance( $id ) { 00040 if ( isset( self::$instances[$id] ) ) { 00041 return self::$instances[$id]; 00042 } 00043 00044 $object = self::newFromId( $id ); 00045 self::$instances[$id] = $object; 00046 return $object; 00047 } 00048 00052 static function clear() { 00053 self::$instances = array(); 00054 } 00055 00064 static function newFromId( $id ) { 00065 global $wgObjectCaches; 00066 00067 if ( !isset( $wgObjectCaches[$id] ) ) { 00068 throw new MWException( "Invalid object cache type \"$id\" requested. " . 00069 "It is not present in \$wgObjectCaches." ); 00070 } 00071 00072 return self::newFromParams( $wgObjectCaches[$id] ); 00073 } 00074 00083 static function newFromParams( $params ) { 00084 if ( isset( $params['factory'] ) ) { 00085 return call_user_func( $params['factory'], $params ); 00086 } elseif ( isset( $params['class'] ) ) { 00087 $class = $params['class']; 00088 return new $class( $params ); 00089 } else { 00090 throw new MWException( "The definition of cache type \"" . print_r( $params, true ) . "\" lacks both " . 00091 "factory and class parameters." ); 00092 } 00093 } 00094 00107 static function newAnything( $params ) { 00108 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; 00109 $candidates = array( $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType ); 00110 foreach ( $candidates as $candidate ) { 00111 if ( $candidate !== CACHE_NONE && $candidate !== CACHE_ANYTHING ) { 00112 return self::getInstance( $candidate ); 00113 } 00114 } 00115 return self::getInstance( CACHE_DB ); 00116 } 00117 00125 static function newAccelerator( $params ) { 00126 if ( function_exists( 'apc_fetch' ) ) { 00127 $id = 'apc'; 00128 } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { 00129 $id = 'xcache'; 00130 } elseif ( function_exists( 'wincache_ucache_get' ) ) { 00131 $id = 'wincache'; 00132 } else { 00133 throw new MWException( "CACHE_ACCEL requested but no suitable object " . 00134 "cache is present. You may want to install APC." ); 00135 } 00136 return self::newFromId( $id ); 00137 } 00138 00150 static function newMemcached( $params ) { 00151 return new MemcachedPhpBagOStuff( $params ); 00152 } 00153 }