objectcache: make the BagOStuff::add() operation more atomic for APC
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 12 Mar 2019 09:49:59 +0000 (02:49 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 15 Mar 2019 00:38:11 +0000 (00:38 +0000)
Change-Id: Ifb72b1c17439c80e6d431d5fe2ec9ad9437e3ad7

includes/libs/objectcache/APCBagOStuff.php
includes/libs/objectcache/APCUBagOStuff.php

index 1fedfaf..847a1eb 100644 (file)
@@ -97,6 +97,14 @@ class APCBagOStuff extends BagOStuff {
                return true;
        }
 
+       public function add( $key, $value, $exptime = 0, $flags = 0 ) {
+               return apc_add(
+                       $key . self::KEY_SUFFIX,
+                       $this->setSerialize( $value ),
+                       $exptime
+               );
+       }
+
        protected function setSerialize( $value ) {
                if ( !$this->nativeSerialize && !$this->isInteger( $value ) ) {
                        $value = serialize( $value );
index fb43d4d..d5f1edc 100644 (file)
@@ -55,6 +55,14 @@ class APCUBagOStuff extends APCBagOStuff {
                return true;
        }
 
+       public function add( $key, $value, $exptime = 0, $flags = 0 ) {
+               return apcu_add(
+                       $key . self::KEY_SUFFIX,
+                       $this->setSerialize( $value ),
+                       $exptime
+               );
+       }
+
        public function delete( $key, $flags = 0 ) {
                apcu_delete( $key . self::KEY_SUFFIX );