Merge "Put skin classes in the Autoloader"
[lhc/web/wiklou.git] / includes / objectcache / MemcachedPhpBagOStuff.php
index 79f3241..c562134 100644 (file)
  *
  * @ingroup Cache
  */
-class MemcachedPhpBagOStuff extends BagOStuff {
-
-       /**
-        * @var MemCachedClientforWiki
-        */
-       protected $client;
+class MemcachedPhpBagOStuff extends MemcachedBagOStuff {
 
        /**
         * Constructor.
@@ -47,24 +42,7 @@ class MemcachedPhpBagOStuff extends BagOStuff {
         * @param $params array
         */
        function __construct( $params ) {
-               if ( !isset( $params['servers'] ) ) {
-                       $params['servers'] = $GLOBALS['wgMemCachedServers'];
-               }
-               if ( !isset( $params['debug'] ) ) {
-                       $params['debug'] = $GLOBALS['wgMemCachedDebug'];
-               }
-               if ( !isset( $params['persistent'] ) ) {
-                       $params['persistent'] = $GLOBALS['wgMemCachedPersistent'];
-               }
-               if  ( !isset( $params['compress_threshold'] ) ) {
-                       $params['compress_threshold'] = 1500;
-               }
-               if ( !isset( $params['timeout'] ) ) {
-                       $params['timeout'] = $GLOBALS['wgMemCachedTimeout'];
-               }
-               if ( !isset( $params['connect_timeout'] ) ) {
-                       $params['connect_timeout'] = 0.1;
-               }
+               $params = $this->applyDefaultParams( $params );
 
                $this->client = new MemCachedClientforWiki( $params );
                $this->client->set_servers( $params['servers'] );
@@ -78,42 +56,15 @@ class MemcachedPhpBagOStuff extends BagOStuff {
                $this->client->set_debug( $debug );
        }
 
-       /**
-        * @param $key string
-        * @return Mixed
-        */
-       public function get( $key ) {
-               return $this->client->get( $this->encodeKey( $key ) );
-       }
-
        /**
         * @param $keys Array
         * @return Array
         */
-       public function getBatch( array $keys ) {
+       public function getMulti( array $keys ) {
                $callback = array( $this, 'encodeKey' );
                return $this->client->get_multi( array_map( $callback, $keys ) );
        }
 
-       /**
-        * @param $key string
-        * @param $value
-        * @param $exptime int
-        * @return bool
-        */
-       public function set( $key, $value, $exptime = 0 ) {
-               return $this->client->set( $this->encodeKey( $key ), $value, $exptime );
-       }
-
-       /**
-        * @param $key string
-        * @param $time int
-        * @return bool
-        */
-       public function delete( $key, $time = 0 ) {
-               return $this->client->delete( $this->encodeKey( $key ), $time );
-       }
-
        /**
         * @param $key
         * @param $timeout int
@@ -130,26 +81,7 @@ class MemcachedPhpBagOStuff extends BagOStuff {
        public function unlock( $key ) {
                return $this->client->unlock( $this->encodeKey( $key ) );
        }
-
-       /**
-        * @param $key string
-        * @param $value int
-        * @return Mixed
-        */
-       public function add( $key, $value, $exptime = 0 ) {
-               return $this->client->add( $this->encodeKey( $key ), $value, $exptime );
-       }
-
-       /**
-        * @param $key string
-        * @param $value int
-        * @param $exptime
-        * @return Mixed
-        */
-       public function replace( $key, $value, $exptime = 0 ) {
-               return $this->client->replace( $this->encodeKey( $key ), $value, $exptime );
-       }
-
+       
        /**
         * @param $key string
         * @param $value int
@@ -167,45 +99,5 @@ class MemcachedPhpBagOStuff extends BagOStuff {
        public function decr( $key, $value = 1 ) {
                return $this->client->decr( $this->encodeKey( $key ), $value );
        }
-
-       /**
-        * Get the underlying client object. This is provided for debugging
-        * purposes.
-        *
-        * @return MemCachedClientforWiki
-        */
-       public function getClient() {
-               return $this->client;
-       }
-
-       /**
-        * Encode a key for use on the wire inside the memcached protocol.
-        *
-        * We encode spaces and line breaks to avoid protocol errors. We encode
-        * the other control characters for compatibility with libmemcached
-        * verify_key. We leave other punctuation alone, to maximise backwards
-        * compatibility.
-        * @return string
-        */
-       public function encodeKey( $key ) {
-               return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/',
-                       array( $this, 'encodeKeyCallback' ), $key );
-       }
-
-       protected function encodeKeyCallback( $m ) {
-               return rawurlencode( $m[0] );
-       }
-
-       /**
-        * Decode a key encoded with encodeKey(). This is provided as a convenience
-        * function for debugging.
-        *
-        * @param $key string
-        *
-        * @return string
-        */
-       public function decodeKey( $key ) {
-               return urldecode( $key );
-       }
 }