Don't require an existence check before calling loadPageData(). Added an accessor...
[lhc/web/wiklou.git] / includes / ObjectCache.php
index 4558ba7..223f5ff 100644 (file)
@@ -4,13 +4,14 @@
  * @subpackage Cache
  */
 
-if (!defined('MEDIAWIKI')) die( "Not a valid entry point\n");
-
-
-# FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
-# It acts as a memcached server with no RAM, that is, all objects are
-# cleared the moment they are set. All set operations succeed and all
-# get operations return null.
+/**
+ * FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
+ * It acts as a memcached server with no RAM, that is, all objects are
+ * cleared the moment they are set. All set operations succeed and all
+ * get operations return null.
+ * @package MediaWiki
+ * @subpackage Cache
+ */
 class FakeMemCachedClient {
        function add ($key, $val, $exp = 0) { return true; }
        function decr ($key, $amt=1) { return null; }
@@ -32,8 +33,9 @@ class FakeMemCachedClient {
 global $wgCaches;
 $wgCaches = array();
 
+/** @todo document */
 function &wfGetCache( $inputType ) {
-       global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug;
+       global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
        $cache = false;
 
        if ( $inputType == CACHE_ANYTHING ) {
@@ -47,17 +49,19 @@ function &wfGetCache( $inputType ) {
        }
 
        if ( $type == CACHE_MEMCACHED ) {
-               if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ){ 
+               if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ){
                        require_once( 'memcached-client.php' );
-                       
-                       class MemCachedClientforWiki extends memcached {
-                               function _debugprint( $text ) {
-                                       wfDebug( "memcached: $text\n" );
+
+                       if (!class_exists("MemcachedClientforWiki")) {
+                               class MemCachedClientforWiki extends memcached {
+                                       function _debugprint( $text ) {
+                                               wfDebug( "memcached: $text\n" );
+                                       }
                                }
                        }
 
-                       $wgCaches[CACHE_DB] = new MemCachedClientforWiki( 
-                               array('persistant' => true, 'compress_threshold' => 1500 ) );
+                       $wgCaches[CACHE_DB] = new MemCachedClientforWiki(
+                               array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
                        $cache =& $wgCaches[CACHE_DB];
                        $cache->set_servers( $wgMemCachedServers );
                        $cache->set_debug( $wgMemCachedDebug );
@@ -86,7 +90,7 @@ function &wfGetCache( $inputType ) {
                }
                $cache =& $wgCaches[CACHE_DB];
        }
-       
+
        if ( $cache === false ) {
                if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
                        $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
@@ -99,17 +103,20 @@ function &wfGetCache( $inputType ) {
 
 function &wfGetMainCache() {
        global $wgMainCacheType;
-       return wfGetCache( $wgMainCacheType );
+       $ret =& wfGetCache( $wgMainCacheType );
+       return $ret;
 }
 
 function &wfGetMessageCacheStorage() {
        global $wgMessageCacheType;
-       return wfGetCache( $wgMessageCacheType );
+       $ret =& wfGetCache( $wgMessageCacheType );
+       return $ret;
 }
 
-function wfGetParserCacheStorage() {
+function &wfGetParserCacheStorage() {
        global $wgParserCacheType;
-       return wfGetCache( $wgParserCacheType );
+       $ret =& wfGetCache( $wgParserCacheType );
+       return $ret;
 }
 
 ?>