objectcache: Ensure an integer put into memcached comes out an integer
authorErik Bernhardson <ebernhardson@wikimedia.org>
Thu, 5 Mar 2015 00:00:10 +0000 (16:00 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 1 Jul 2015 03:51:55 +0000 (03:51 +0000)
Some parts of resourceloader put an integer into the BagOStuff
and rejects any value it pulls back out that is not an integer.
This patch updates the memcached client behind the BagOStuff to
flag integer values and convert them back to integer when recieved.
The end result is shaving several seconds off the time it takes to
request a CSS or JS file in certain configurations.

Bug: 60563
Change-Id: Ie4dc8cf2c2cd232a2c167b4075ff4254b656bcbc

includes/objectcache/MemcachedClient.php

index 6912864..5010b89 100644 (file)
@@ -94,6 +94,11 @@ class MWMemcached {
         */
        const COMPRESSED = 2;
 
+       /**
+        * Flag: indicates data is an integer
+        */
+       const INTVAL = 4;
+
        // }}}
 
        /**
@@ -979,6 +984,8 @@ class MWMemcached {
                                         */
                                        if ( $flags & self::SERIALIZED ) {
                                                $ret[$rkey] = unserialize( $ret[$rkey] );
+                                       } elseif ( $flags & self::INTVAL ) {
+                                               $ret[$rkey] = intval( $ret[$rkey] );
                                        }
                                }
 
@@ -1027,7 +1034,9 @@ class MWMemcached {
 
                $flags = 0;
 
-               if ( !is_scalar( $val ) ) {
+               if ( is_int( $val ) ) {
+                       $flags |= self::INTVAL;
+               } elseif ( !is_scalar( $val ) ) {
                        $val = serialize( $val );
                        $flags |= self::SERIALIZED;
                        if ( $this->_debug ) {