Change getCacheSetOptions() callers to use "Database"
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Oct 2015 05:06:46 +0000 (22:06 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Oct 2015 05:06:46 +0000 (22:06 -0700)
* This is less verbose that DatabaseBase
* Also add a few WAN cache doc comments

Change-Id: I5b6de6d0ffa06753ea96c50b63db7dae796475dc

includes/User.php
includes/actions/InfoAction.php
includes/changetags/ChangeTags.php
includes/filerepo/LocalRepo.php
includes/filerepo/file/LocalFile.php
includes/interwiki/Interwiki.php
includes/libs/objectcache/WANObjectCache.php

index 20b75bf..75649a7 100644 (file)
@@ -458,7 +458,7 @@ class User implements IDBAccessObject {
                $data['mVersion'] = self::VERSION;
                $key = wfMemcKey( 'user', 'id', $this->mId );
 
-               $opts = DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
+               $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
                ObjectCache::getMainWANInstance()->set( $key, $data, 3600, $opts );
        }
 
index 4e74ed3..78dd5fe 100644 (file)
@@ -682,7 +682,7 @@ class InfoAction extends FormlessAction {
                                $dbr = wfGetDB( DB_SLAVE );
                                $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
 
-                               $setOpts += DatabaseBase::getCacheSetOptions( $dbr, $dbrWatchlist );
+                               $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
 
                                $result = array();
 
index e1b9b27..5531245 100644 (file)
@@ -1091,7 +1091,7 @@ class ChangeTags {
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'active-tags' ),
                        function ( $oldValue, &$ttl, array &$setOpts ) {
-                               $setOpts += DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
+                               $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
 
                                // Ask extensions which tags they consider active
                                $extensionActive = array();
@@ -1135,7 +1135,7 @@ class ChangeTags {
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
                                $dbr = wfGetDB( DB_SLAVE );
 
-                               $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+                               $setOpts += Database::getCacheSetOptions( $dbr );
 
                                $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', array(), $fname );
 
@@ -1160,7 +1160,7 @@ class ChangeTags {
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'valid-tags-hook' ),
                        function ( $oldValue, &$ttl, array &$setOpts ) {
-                               $setOpts += DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
+                               $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
 
                                $tags = array();
                                Hooks::run( 'ListDefinedTags', array( &$tags ) );
@@ -1221,7 +1221,7 @@ class ChangeTags {
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
                                $dbr = wfGetDB( DB_SLAVE, 'vslow' );
 
-                               $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+                               $setOpts += Database::getCacheSetOptions( $dbr );
 
                                $res = $dbr->select(
                                        'change_tag',
index 389f081..02d859f 100644 (file)
@@ -205,7 +205,7 @@ class LocalRepo extends FileRepo {
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $that, $title ) {
                                $dbr = $that->getSlaveDB(); // possibly remote DB
 
-                               $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+                               $setOpts += Database::getCacheSetOptions( $dbr );
 
                                if ( $title instanceof Title ) {
                                        $row = $dbr->selectRow(
index d5179cb..50b9caf 100644 (file)
@@ -309,7 +309,7 @@ class LocalFile extends File {
 
                // Cache presence for 1 week and negatives for 1 day
                $ttl = $this->fileExists ? 86400 * 7 : 86400;
-               $opts = DatabaseBase::getCacheSetOptions( $this->repo->getSlaveDB() );
+               $opts = Database::getCacheSetOptions( $this->repo->getSlaveDB() );
                ObjectCache::getMainWANInstance()->set( $key, $cacheVal, $ttl, $opts );
        }
 
index 89aeaae..7a49f9b 100644 (file)
@@ -221,7 +221,7 @@ class Interwiki {
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix ) {
                                $dbr = wfGetDB( DB_SLAVE );
 
-                               $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+                               $setOpts += Database::getCacheSetOptions( $dbr );
 
                                $row = $dbr->selectRow(
                                        'interwiki',
index b1d3ec2..7e70e4b 100644 (file)
@@ -269,10 +269,12 @@ class WANObjectCache {
         *   - d) T1 reads the row and calls set() due to a cache miss
         *   - e) Stale value is stuck in cache
         *
+        * Setting 'lag' helps avoids keys getting stuck in long-term stale states.
+        *
         * Example usage:
         * @code
         *     $dbr = wfGetDB( DB_SLAVE );
-        *     $setOpts = DatabaseBase::getCacheSetOptions( $dbr );
+        *     $setOpts = Database::getCacheSetOptions( $dbr );
         *     // Fetch the row from the DB
         *     $row = $dbr->selectRow( ... );
         *     $key = wfMemcKey( 'building', $buildingId );
@@ -505,6 +507,7 @@ class WANObjectCache {
         * can be set dynamically by altering $ttl in the callback (by reference).
         * The $setOpts array can be altered and is given to set() when called;
         * it is recommended to set the 'since' field to avoid race conditions.
+        * Setting 'lag' helps avoids keys getting stuck in long-term stale states.
         *
         * Usually, callbacks ignore the current value, but it can be used
         * to maintain "most recent X" values that come from time or sequence
@@ -529,7 +532,7 @@ class WANObjectCache {
         *         function ( $oldValue, &$ttl, array &$setOpts ) {
         *             $dbr = wfGetDB( DB_SLAVE );
         *             // Account for any snapshot/slave lag
-        *             $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+        *             $setOpts += Database::getCacheSetOptions( $dbr );
         *
         *             return $dbr->selectRow( ... );
         *        },
@@ -547,7 +550,7 @@ class WANObjectCache {
         *         function ( $oldValue, &$ttl, array &$setOpts ) {
         *             $dbr = wfGetDB( DB_SLAVE );
         *             // Account for any snapshot/slave lag
-        *             $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+        *             $setOpts += Database::getCacheSetOptions( $dbr );
         *
         *             return CatConfig::newFromRow( $dbr->selectRow( ... ) );
         *        },
@@ -570,7 +573,7 @@ class WANObjectCache {
         *             // Determine new value from the DB
         *             $dbr = wfGetDB( DB_SLAVE );
         *             // Account for any snapshot/slave lag
-        *             $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+        *             $setOpts += Database::getCacheSetOptions( $dbr );
         *
         *             return CatState::newFromResults( $dbr->select( ... ) );
         *        },
@@ -595,7 +598,7 @@ class WANObjectCache {
         *         function ( $oldValue, &$ttl, array &$setOpts ) {
         *             $dbr = wfGetDB( DB_SLAVE );
         *             // Account for any snapshot/slave lag
-        *             $setOpts += DatabaseBase::getCacheSetOptions( $dbr );
+        *             $setOpts += Database::getCacheSetOptions( $dbr );
         *
         *             // Start off with the last cached list
         *             $list = $oldValue ?: array();