Add TTL_PROC_* constants for clarity
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 5 May 2016 23:40:26 +0000 (16:40 -0700)
committerOri.livneh <ori@wikimedia.org>
Fri, 6 May 2016 23:45:41 +0000 (23:45 +0000)
This makes the reason for the cache times more obvious

Change-Id: Ie75df6be77c513feeb6cff3417ccbc124a6a1141

includes/SiteStats.php
includes/changetags/ChangeTags.php
includes/filerepo/LocalRepo.php
includes/jobqueue/JobQueueGroup.php
includes/libs/objectcache/IExpiringStore.php

index 215378b..6c536dd 100644 (file)
@@ -193,7 +193,7 @@ class SiteStats {
                                        __METHOD__
                                );
                        },
-                       [ 'pcTTL' => 10 ]
+                       [ 'pcTTL' => $cache::TTL_PROC_LONG ]
                );
        }
 
index 9db1697..2d4d20f 100644 (file)
@@ -1134,7 +1134,7 @@ class ChangeTags {
        public static function listExtensionActivatedTags() {
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'active-tags' ),
-                       300,
+                       WANObjectCache::TTL_MINUTE * 5,
                        function ( $oldValue, &$ttl, array &$setOpts ) {
                                $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
 
@@ -1145,8 +1145,8 @@ class ChangeTags {
                        },
                        [
                                'checkKeys' => [ wfMemcKey( 'active-tags' ) ],
-                               'lockTSE' => 300,
-                               'pcTTL' => 30
+                               'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
+                               'pcTTL' => WANObjectCache::TTL_PROC_LONG
                        ]
                );
        }
@@ -1179,7 +1179,7 @@ class ChangeTags {
 
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'valid-tags-db' ),
-                       300,
+                       WANObjectCache::TTL_MINUTE * 5,
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
                                $dbr = wfGetDB( DB_SLAVE );
 
@@ -1191,8 +1191,8 @@ class ChangeTags {
                        },
                        [
                                'checkKeys' => [ wfMemcKey( 'valid-tags-db' ) ],
-                               'lockTSE' => 300,
-                               'pcTTL' => 30
+                               'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
+                               'pcTTL' => WANObjectCache::TTL_PROC_LONG
                        ]
                );
        }
@@ -1209,7 +1209,7 @@ class ChangeTags {
        public static function listExtensionDefinedTags() {
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'valid-tags-hook' ),
-                       300,
+                       WANObjectCache::TTL_MINUTE * 5,
                        function ( $oldValue, &$ttl, array &$setOpts ) {
                                $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
 
@@ -1219,8 +1219,8 @@ class ChangeTags {
                        },
                        [
                                'checkKeys' => [ wfMemcKey( 'valid-tags-hook' ) ],
-                               'lockTSE' => 300,
-                               'pcTTL' => 30
+                               'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
+                               'pcTTL' => WANObjectCache::TTL_PROC_LONG
                        ]
                );
        }
@@ -1264,7 +1264,7 @@ class ChangeTags {
                $fname = __METHOD__;
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        wfMemcKey( 'change-tag-statistics' ),
-                       300,
+                       WANObjectCache::TTL_MINUTE * 5,
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
                                $dbr = wfGetDB( DB_SLAVE, 'vslow' );
 
@@ -1287,8 +1287,8 @@ class ChangeTags {
                        },
                        [
                                'checkKeys' => [ wfMemcKey( 'change-tag-statistics' ) ],
-                               'lockTSE' => 300,
-                               'pcTTL' => 30
+                               'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
+                               'pcTTL' => WANObjectCache::TTL_PROC_LONG
                        ]
                );
        }
index 8248699..eaec151 100644 (file)
@@ -227,7 +227,7 @@ class LocalRepo extends FileRepo {
                                        ? Title::makeTitle( $row->rd_namespace, $row->rd_title )->getDBkey()
                                        : ''; // negative cache
                        },
-                       [ 'pcTTL' => 30 ]
+                       [ 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
                );
 
                // @note: also checks " " for b/c
index 2dd0615..a4b3241 100644 (file)
@@ -407,7 +407,7 @@ class JobQueueGroup {
 
                                        return [ 'v' => $wgConf->getConfig( $wiki, $name ) ];
                                },
-                               [ 'pcTTL' => 30 ]
+                               [ 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
                        );
 
                        return $value['v'];
index fa465c7..91e7934 100644 (file)
@@ -29,7 +29,6 @@
  * @since 1.27
  */
 interface IExpiringStore {
-
        // Constants for TTL values, in seconds
        const TTL_MINUTE = 60;
        const TTL_HOUR = 3600;
@@ -38,5 +37,9 @@ interface IExpiringStore {
        const TTL_MONTH = 2592000; // 30 * 24 * 3600
        const TTL_YEAR = 31536000; // 365 * 24 * 3600
 
+       // Shorthand process cache TTLs (useful for web requests and CLI mode)
+       const TTL_PROC_SHORT = 3; // reasonably strict cache time that last the life of quick requests
+       const TTL_PROC_LONG = 30; // loose cache time that can survive slow web requests
+
        const TTL_INDEFINITE = 0;
 }