3 * Functions to get cache objects
9 static $instances = array();
12 * Get a cached instance of the specified type of cache object.
18 static function getInstance( $id ) {
19 if ( isset( self
::$instances[$id] ) ) {
20 return self
::$instances[$id];
23 $object = self
::newFromId( $id );
24 self
::$instances[$id] = $object;
29 * Clear all the cached instances.
31 static function clear() {
32 self
::$instances = array();
36 * Create a new cache object of the specified type.
42 static function newFromId( $id ) {
43 global $wgObjectCaches;
45 if ( !isset( $wgObjectCaches[$id] ) ) {
46 throw new MWException( "Invalid object cache type \"$id\" requested. " .
47 "It is not present in \$wgObjectCaches." );
50 return self
::newFromParams( $wgObjectCaches[$id] );
54 * Create a new cache object from parameters
56 * @param $params array
60 static function newFromParams( $params ) {
61 if ( isset( $params['factory'] ) ) {
62 return call_user_func( $params['factory'], $params );
63 } elseif ( isset( $params['class'] ) ) {
64 $class = $params['class'];
65 return new $class( $params );
67 throw new MWException( "The definition of cache type \"" . print_r( $params, true ) . "\" lacks both " .
68 "factory and class parameters." );
73 * Factory function referenced from DefaultSettings.php for CACHE_ANYTHING
75 static function newAnything( $params ) {
76 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
77 $candidates = array( $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType );
78 foreach ( $candidates as $candidate ) {
79 if ( $candidate !== CACHE_NONE
&& $candidate !== CACHE_ANYTHING
) {
80 return self
::getInstance( $candidate );
83 return self
::getInstance( CACHE_DB
);
87 * Factory function referenced from DefaultSettings.php for CACHE_ACCEL.
91 static function newAccelerator( $params ) {
92 if ( function_exists( 'apc_fetch') ) {
94 } elseif( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
96 } elseif( function_exists( 'wincache_ucache_get' ) ) {
99 throw new MWException( "CACHE_ACCEL requested but no suitable object " .
100 "cache is present. You may want to install APC." );
102 return self
::newFromId( $id );
106 * Factory function that creates a memcached client object.
107 * The idea of this is that it might eventually detect and automatically
108 * support the PECL extension, assuming someone can get it to compile.
110 * @param $params array
112 * @return MemcachedPhpBagOStuff
114 static function newMemcached( $params ) {
115 return new MemcachedPhpBagOStuff( $params );