HashBagOStuff: use the value itself as the CAS token
authorTim Starling <tstarling@wikimedia.org>
Tue, 7 Oct 2014 05:24:45 +0000 (16:24 +1100)
committerTim Starling <tstarling@wikimedia.org>
Tue, 7 Oct 2014 05:29:57 +0000 (16:29 +1100)
Avoid an unnecessary serialize() call on get() requests, which makes it
faster and also happens to work around a nasty crash bug which is
causing lots of segfaults right now.

CAS semantics should be the same, if the caller handles a CAS token in
an opaque way and does not assume it is a string. I could only find one
caller of cas() in core and WMF deployed extensions, and that is
BagOStuff::mergeViaCas(), which does correctly handle CAS tokens of any
type.

Bug: 71724
Change-Id: I0b0b5f0157c005ec7f76210dfb8576c056314733

includes/objectcache/HashBagOStuff.php

index 6e50a8c..06a0865 100644 (file)
@@ -65,7 +65,7 @@ class HashBagOStuff extends BagOStuff {
                        return false;
                }
 
-               $casToken = serialize( $this->bag[$key][0] );
+               $casToken = $this->bag[$key][0];
 
                return $this->bag[$key][0];
        }
@@ -89,7 +89,7 @@ class HashBagOStuff extends BagOStuff {
         * @return bool
         */
        function cas( $casToken, $key, $value, $exptime = 0 ) {
-               if ( serialize( $this->get( $key ) ) === $casToken ) {
+               if ( $this->get( $key ) === $casToken ) {
                        return $this->set( $key, $value, $exptime );
                }