MediaWiki
REL1_19
|
00001 <?php 00008 class ObjectCache { 00009 static $instances = array(); 00010 00018 static function getInstance( $id ) { 00019 if ( isset( self::$instances[$id] ) ) { 00020 return self::$instances[$id]; 00021 } 00022 00023 $object = self::newFromId( $id ); 00024 self::$instances[$id] = $object; 00025 return $object; 00026 } 00027 00031 static function clear() { 00032 self::$instances = array(); 00033 } 00034 00042 static function newFromId( $id ) { 00043 global $wgObjectCaches; 00044 00045 if ( !isset( $wgObjectCaches[$id] ) ) { 00046 throw new MWException( "Invalid object cache type \"$id\" requested. " . 00047 "It is not present in \$wgObjectCaches." ); 00048 } 00049 00050 return self::newFromParams( $wgObjectCaches[$id] ); 00051 } 00052 00060 static function newFromParams( $params ) { 00061 if ( isset( $params['factory'] ) ) { 00062 return call_user_func( $params['factory'], $params ); 00063 } elseif ( isset( $params['class'] ) ) { 00064 $class = $params['class']; 00065 return new $class( $params ); 00066 } else { 00067 throw new MWException( "The definition of cache type \"" . print_r( $params, true ) . "\" lacks both " . 00068 "factory and class parameters." ); 00069 } 00070 } 00071 00075 static function newAnything( $params ) { 00076 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; 00077 $candidates = array( $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType ); 00078 foreach ( $candidates as $candidate ) { 00079 if ( $candidate !== CACHE_NONE && $candidate !== CACHE_ANYTHING ) { 00080 return self::getInstance( $candidate ); 00081 } 00082 } 00083 return self::getInstance( CACHE_DB ); 00084 } 00085 00091 static function newAccelerator( $params ) { 00092 if ( function_exists( 'apc_fetch') ) { 00093 $id = 'apc'; 00094 } elseif( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { 00095 $id = 'xcache'; 00096 } elseif( function_exists( 'wincache_ucache_get' ) ) { 00097 $id = 'wincache'; 00098 } else { 00099 throw new MWException( "CACHE_ACCEL requested but no suitable object " . 00100 "cache is present. You may want to install APC." ); 00101 } 00102 return self::newFromId( $id ); 00103 } 00104 00114 static function newMemcached( $params ) { 00115 return new MemcachedPhpBagOStuff( $params ); 00116 } 00117 }