3 * Functions to get cache objects
9 static $instances = array();
12 * Get a cached instance of the specified type of cache object.
14 static function getInstance( $id ) {
15 if ( isset( self
::$instances[$id] ) ) {
16 return self
::$instances[$id];
19 $object = self
::newFromId( $id );
20 self
::$instances[$id] = $object;
25 * Create a new cache object of the specified type.
27 static function newFromId( $id ) {
28 global $wgObjectCaches;
30 if ( !isset( $wgObjectCaches[$id] ) ) {
31 throw new MWException( "Invalid object cache type \"$id\" requested. " .
32 "It is not present in \$wgObjectCaches." );
35 return self
::newFromParams( $wgObjectCaches[$id] );
39 * Create a new cache object from parameters
41 static function newFromParams( $params ) {
42 if ( isset( $params['factory'] ) ) {
43 return call_user_func( $params['factory'], $params );
44 } elseif ( isset( $params['class'] ) ) {
45 $class = $params['class'];
46 return new $class( $params );
48 throw new MWException( "The definition of cache type \"$id\" lacks both " .
49 "factory and class parameters." );
54 * Factory function referenced from DefaultSettings.php for CACHE_ANYTHING
56 static function newAnything( $params ) {
57 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
58 $candidates = array( $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType );
59 foreach ( $candidates as $candidate ) {
60 if ( $candidate !== CACHE_NONE
&& $candidate !== CACHE_ANYTHING
) {
61 return self
::newFromId( $candidate );
64 return self
::newFromId( CACHE_DB
);
68 * Factory function referenced from DefaultSettings.php for CACHE_ACCEL.
70 static function newAccelerator( $params ) {
71 if ( function_exists( 'eaccelerator_get' ) ) {
73 } elseif ( function_exists( 'apc_fetch') ) {
75 } elseif( function_exists( 'xcache_get' ) ) {
77 } elseif( function_exists( 'wincache_ucache_get' ) ) {
80 throw new MWException( "CACHE_ACCEL requested but no suitable object " .
81 "cache is present. You may want to install APC." );
83 return self
::newFromId( $id );
87 * Factory function that creates a memcached client object.
88 * The idea of this is that it might eventually detect and automatically
89 * support the PECL extension, assuming someone can get it to compile.
91 static function newMemcached( $params ) {
92 return new MemcachedPhpBagOStuff( $params );