Merge "objectcache: Fix grammar error in BagOStuff::getWithToken doc"
[lhc/web/wiklou.git] / includes / libs / objectcache / BagOStuff.php
index fc75f56..5dfec6e 100644 (file)
@@ -67,6 +67,8 @@ abstract class BagOStuff implements LoggerAwareInterface {
        /** Bitfield constants for get()/getMulti() */
        const READ_LATEST = 1; // use latest data for replicated stores
        const READ_VERIFIED = 2; // promise that caller can tell when keys are stale
+       /** Bitfield constants for set()/merge() */
+       const WRITE_SYNC = 1; // synchronously write to all locations for replicated stores
 
        public function __construct( array $params = array() ) {
                if ( isset( $params['logger'] ) ) {
@@ -158,6 +160,7 @@ abstract class BagOStuff implements LoggerAwareInterface {
         * @param mixed $casToken
         * @param integer $flags Bitfield of BagOStuff::READ_* constants [optional]
         * @return mixed Returns false on failure and if the item does not exist
+        * @throws Exception
         */
        protected function getWithToken( $key, &$casToken, $flags = 0 ) {
                throw new Exception( __METHOD__ . ' not implemented.' );
@@ -169,9 +172,10 @@ abstract class BagOStuff implements LoggerAwareInterface {
         * @param string $key
         * @param mixed $value
         * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
+        * @param int $flags Bitfield of BagOStuff::WRITE_* constants
         * @return bool Success
         */
-       abstract public function set( $key, $value, $exptime = 0 );
+       abstract public function set( $key, $value, $exptime = 0, $flags = 0 );
 
        /**
         * Delete an item
@@ -191,15 +195,16 @@ abstract class BagOStuff implements LoggerAwareInterface {
         * @param callable $callback Callback method to be executed
         * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
         * @param int $attempts The amount of times to attempt a merge in case of failure
+        * @param int $flags Bitfield of BagOStuff::WRITE_* constants
         * @return bool Success
         * @throws InvalidArgumentException
         */
-       public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
+       public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
                if ( !is_callable( $callback ) ) {
                        throw new InvalidArgumentException( "Got invalid callback." );
                }
 
-               return $this->mergeViaLock( $key, $callback, $exptime, $attempts );
+               return $this->mergeViaLock( $key, $callback, $exptime, $attempts, $flags );
        }
 
        /**
@@ -262,9 +267,10 @@ abstract class BagOStuff implements LoggerAwareInterface {
         * @param callable $callback Callback method to be executed
         * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
         * @param int $attempts The amount of times to attempt a merge in case of failure
+        * @param int $flags Bitfield of BagOStuff::WRITE_* constants
         * @return bool Success
         */
-       protected function mergeViaLock( $key, $callback, $exptime = 0, $attempts = 10 ) {
+       protected function mergeViaLock( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
                if ( !$this->lock( $key, 6 ) ) {
                        return false;
                }
@@ -279,7 +285,7 @@ abstract class BagOStuff implements LoggerAwareInterface {
                        if ( $value === false ) {
                                $success = true; // do nothing
                        } else {
-                               $success = $this->set( $key, $value, $exptime ); // set the new value
+                               $success = $this->set( $key, $value, $exptime, $flags ); // set the new value
                        }
                }