Merge "Document WAN cache FLD_* constants"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 12 May 2016 19:44:17 +0000 (19:44 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 12 May 2016 19:44:17 +0000 (19:44 +0000)
1  2 
includes/libs/objectcache/WANObjectCache.php

@@@ -110,12 -110,12 +110,12 @@@ class WANObjectCache implements IExpiri
        /** Cache format version number */
        const VERSION = 1;
  
-       const FLD_VERSION = 0;
-       const FLD_VALUE = 1;
-       const FLD_TTL = 2;
-       const FLD_TIME = 3;
-       const FLD_FLAGS = 4;
-       const FLD_HOLDOFF = 5;
+       const FLD_VERSION = 0; // key to cache version number
+       const FLD_VALUE = 1; // key to the cached value
+       const FLD_TTL = 2; // key to the original TTL
+       const FLD_TIME = 3; // key to the cache time
+       const FLD_FLAGS = 4; // key to the flags bitfield
+       const FLD_HOLDOFF = 5; // key to any hold-off TTL
  
        /** @var integer Treat this value as expired-on-arrival */
        const FLG_STALE = 1;
         * @return bool Success
         */
        final public function set( $key, $value, $ttl = 0, array $opts = [] ) {
 +              $now = microtime( true );
                $lockTSE = isset( $opts['lockTSE'] ) ? $opts['lockTSE'] : self::TSE_NONE;
 -              $age = isset( $opts['since'] ) ? max( 0, microtime( true ) - $opts['since'] ) : 0;
 +              $age = isset( $opts['since'] ) ? max( 0, $now - $opts['since'] ) : 0;
                $lag = isset( $opts['lag'] ) ? $opts['lag'] : 0;
  
                // Do not cache potentially uncommitted data as it might get rolled back
                }
  
                // Wrap that value with time/TTL/version metadata
 -              $wrapped = $this->wrap( $value, $ttl ) + $wrapExtra;
 +              $wrapped = $this->wrap( $value, $ttl, $now ) + $wrapExtra;
  
                $func = function ( $cache, $key, $cWrapped ) use ( $wrapped ) {
                        return ( is_string( $cWrapped ) )
         *
         * @param mixed $value
         * @param integer $ttl [0=forever]
 +       * @param float $now Unix Current timestamp just before calling set()
         * @return array
         */
 -      protected function wrap( $value, $ttl ) {
 +      protected function wrap( $value, $ttl, $now ) {
                return [
                        self::FLD_VERSION => self::VERSION,
                        self::FLD_VALUE => $value,
                        self::FLD_TTL => $ttl,
 -                      self::FLD_TIME => microtime( true )
 +                      self::FLD_TIME => $now
                ];
        }
  
         * Do not use this method outside WANObjectCache
         *
         * @param array|string|bool $wrapped
 -       * @param float $now Unix Current timestamp (preferrable pre-query)
 +       * @param float $now Unix Current timestamp (preferrably pre-query)
         * @return array (mixed; false if absent/invalid, current time left)
         */
        protected function unwrap( $wrapped, $now ) {