Rename DB_SLAVE constant to DB_REPLICA
[lhc/web/wiklou.git] / includes / objectcache / MemcachedPeclBagOStuff.php
index aa21cbb..aefda79 100644 (file)
@@ -42,6 +42,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
         *   - serializer:          May be either "php" or "igbinary". Igbinary produces more compact
         *                          values, but serialization is much slower unless the php.ini option
         *                          igbinary.compact_strings is off.
+        *   - use_binary_protocol  Whether to enable the binary protocol (default is ASCII) (boolean)
         * @param array $params
         * @throws InvalidArgumentException
         */
@@ -62,8 +63,8 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                        $this->client = new Memcached;
                }
 
-               if ( !isset( $params['serializer'] ) ) {
-                       $params['serializer'] = 'php';
+               if ( $params['use_binary_protocol'] ) {
+                       $this->client->setOption( Memcached::OPT_BINARY_PROTOCOL, true );
                }
 
                if ( isset( $params['retry_timeout'] ) ) {
@@ -112,13 +113,27 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                                        __CLASS__ . ': invalid value for serializer parameter'
                                );
                }
-               $servers = array();
+               $servers = [];
                foreach ( $params['servers'] as $host ) {
                        $servers[] = IP::splitHostAndPort( $host ); // (ip, port)
                }
                $this->client->addServers( $servers );
        }
 
+       protected function applyDefaultParams( $params ) {
+               $params = parent::applyDefaultParams( $params );
+
+               if ( !isset( $params['use_binary_protocol'] ) ) {
+                       $params['use_binary_protocol'] = false;
+               }
+
+               if ( !isset( $params['serializer'] ) ) {
+                       $params['serializer'] = 'php';
+               }
+
+               return $params;
+       }
+
        protected function getWithToken( $key, &$casToken, $flags = 0 ) {
                $this->debugLog( "get($key)" );
                $result = $this->client->get( $this->validateKeyEncoding( $key ), null, $casToken );
@@ -189,7 +204,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                                break;
                        default:
                                $msg = $this->client->getResultMessage();
-                               $logCtx = array();
+                               $logCtx = [];
                                if ( $key !== false ) {
                                        $server = $this->client->getServerByKey( $key );
                                        $logCtx['memcached-server'] = "{$server['host']}:{$server['port']}";
@@ -209,7 +224,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                foreach ( $keys as $key ) {
                        $this->validateKeyEncoding( $key );
                }
-               $result = $this->client->getMulti( $keys ) ?: array();
+               $result = $this->client->getMulti( $keys ) ?: [];
                return $this->checkResult( false, $result );
        }
 
@@ -226,4 +241,10 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                $result = $this->client->setMulti( $data, $this->fixExpiry( $exptime ) );
                return $this->checkResult( false, $result );
        }
+
+       public function changeTTL( $key, $expiry = 0 ) {
+               $this->debugLog( "touch($key)" );
+               $result = $this->client->touch( $key, $expiry );
+               return $this->checkResult( $key, $result );
+       }
 }