Merge "RCFilters: Style the Saved Links placeholder and add a title"
[lhc/web/wiklou.git] / includes / libs / objectcache / MemcachedClient.php
index 59322b6..a94f86a 100644 (file)
@@ -360,6 +360,48 @@ class MemcachedClient {
                return false;
        }
 
+       /**
+        * Changes the TTL on a key from the server to $time
+        *
+        * @param string $key Key
+        * @param int $time TTL in seconds
+        *
+        * @return bool True on success, false on failure
+        */
+       public function touch( $key, $time = 0 ) {
+               if ( !$this->_active ) {
+                       return false;
+               }
+
+               $sock = $this->get_sock( $key );
+               if ( !is_resource( $sock ) ) {
+                       return false;
+               }
+
+               $key = is_array( $key ) ? $key[1] : $key;
+
+               if ( isset( $this->stats['touch'] ) ) {
+                       $this->stats['touch']++;
+               } else {
+                       $this->stats['touch'] = 1;
+               }
+               $cmd = "touch $key $time\r\n";
+               if ( !$this->_fwrite( $sock, $cmd ) ) {
+                       return false;
+               }
+               $res = $this->_fgets( $sock );
+
+               if ( $this->_debug ) {
+                       $this->_debugprint( sprintf( "MemCache: touch %s (%s)", $key, $res ) );
+               }
+
+               if ( $res == "TOUCHED" ) {
+                       return true;
+               }
+
+               return false;
+       }
+
        /**
         * @param string $key
         * @param int $timeout
@@ -487,7 +529,7 @@ class MemcachedClient {
         */
        public function get_multi( $keys ) {
                if ( !$this->_active ) {
-                       return false;
+                       return array();
                }
 
                if ( isset( $this->stats['get_multi'] ) ) {
@@ -1072,9 +1114,13 @@ class MemcachedClient {
                if ( $this->_debug ) {
                        $this->_debugprint( sprintf( "%s %s (%s)", $cmd, $key, $line ) );
                }
-               if ( $line == "STORED" ) {
+               if ( $line === "STORED" ) {
+                       return true;
+               } elseif ( $line === "NOT_STORED" && $cmd === "set" ) {
+                       // "Not stored" is always used as the mcrouter response with AllAsyncRoute
                        return true;
                }
+
                return false;
        }