r102557 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102556‎ | r102557 | r102558 >
Date:18:55, 9 November 2011
Author:catrope
Status:ok
Tags:
Comment:
[RL2] Per r102412 CR, make the cache timeout configurable per-repo. Also kill $wgGadgetsForeignCacheTimeout and make the 'cacheTimeout' property just default to 600 if not set.
Modified paths:
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/ForeignAPIGadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -44,16 +44,18 @@
4545 * 'dbUser' => 'username', // User name for the foreign wiki's database
4646 * 'dbPassword' => 'password', // Password for the foreign wiki's database
4747 * 'dbName' => 'mediawikiwiki', // Name of the foreign wiki's database
48 - * // TODO: Make this the default?
 48+ * // TODO: Make this the default?
4949 * 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT // Use this value unless you know what you're doing
5050 * 'tablePrefix' => 'mw_', // Table prefix for the foreign wiki's database, or '' if no prefix
51 - * 'hasSharedCache' => true, // Whether the foreign wiki's cache is accessible through $wgMemc
 51+ * 'hasSharedCache' => true, // Whether the foreign wiki's cache is accessible through $wgMemc
 52+ * 'cacheTimeout' => 600, // Expiry for locally cached data, in seconds (optional; default is 600)
5253 * );
5354 *
5455 * For foreign API-based gadget repositories, use:
5556 * $wgGadgetRepositories[] = array(
5657 * 'class' => 'ForeignAPIGadgetRepo',
5758 * 'source' => 'mediawikiwiki',
 59+ * 'cacheTimeout' => 600, // Expiry for locally cached data, in seconds (optional; default is 600)
5860 * );
5961 */
6062 $wgGadgetRepositories = array();
@@ -66,18 +68,6 @@
6769 */
6870 $wgGadgetEnableSharing = true;
6971
70 -/**
71 - * For how long gadget metadata obtained from a foreign wiki should be cached locally.
72 - * Defaults to 600 seconds (10 minutes). If set to zero, data will be cached FOREVER.
73 - *
74 - * If you have a gadget repository (see $wgGadgetRepositories) with 'class' => 'ForeignAPIGadgetRepo',
75 - * or a gadget repository with 'class' => 'ForeignDBGadgetRepo' and 'hasSharedCache' => false,
76 - * this value controls how long it will take before changes to gadgets on the foreign wiki
77 - * will show up on your wiki. For local gadgets and for foreign repositories with 'hasSharedCache' => true,
78 - * changes will show up immediately.
79 - */
80 -$wgGadgetsForeignCacheTimeout = 600;
81 -
8272 /*** Setup ***/
8373
8474 define( 'NS_GADGET', 2300 );
Index: branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php
@@ -2,7 +2,7 @@
33 /**
44 * Gadget repository that gets its gadgets from a foreign database.
55 *
6 - * Options (all of these are MANDATORY):
 6+ * Options (all of these are MANDATORY except cacheTimeout):
77 * 'source': Name of the source these gadgets are loaded from, as defined in ResourceLoader
88 * 'dbType': Database type, see DatabaseBase::factory()
99 * 'dbServer': Database host
@@ -12,11 +12,13 @@
1313 * 'dbFlags': Bitmap of the DBO_* flags. Recommended value is ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT
1414 * 'tablePrefix': Table prefix
1515 * 'hasSharedCache': Whether the foreign wiki's cache is accessible through $wgMemc
 16+ * 'cacheTimeout': Expiry for locally cached data, in seconds (optional; default is 600)
1617 */
1718 class ForeignDBGadgetRepo extends LocalGadgetRepo {
1819 protected $db = null;
1920
20 - protected $source, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags, $tablePrefix, $hasSharedCache;
 21+ protected $source, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags, $tablePrefix, $hasSharedCache,
 22+ $cacheTimeout = 600;
2123
2224 /**
2325 * Constructor.
@@ -30,6 +32,10 @@
3133 foreach ( $optionKeys as $optionKey ) {
3234 $this->{$optionKey} = $options[$optionKey];
3335 }
 36+
 37+ if ( isset( $options['cacheTimeout'] ) ) {
 38+ $this->cacheTimeout = $options['cacheTimeout'];
 39+ }
3440 }
3541
3642 public function isWriteable() {
@@ -92,14 +98,13 @@
9399 }
94100
95101 protected function getCacheExpiry( $id ) {
96 - global $wgGadgetsForeignCacheTimeout;
97102 if ( $this->hasSharedCache ) {
98103 // We're using the other wiki's local cache, and
99104 // the other wiki will be handling invalidation.
100105 // So cache forever.
101106 return 0;
102107 } else {
103 - return $wgGadgetsForeignCacheTimeout;
 108+ return $this->cacheTimeout;
104109 }
105110 }
106111
Index: branches/RL2/extensions/Gadgets/backend/ForeignAPIGadgetRepo.php
@@ -4,6 +4,7 @@
55 *
66 * Options (all of these are MANDATORY):
77 * 'source': Name of the source these gadgets are loaded from, as defined in ResourceLoader
 8+ * 'cacheTimeout': Expiry for locally cached data, in seconds (optional; default is 600)
89 */
910 class ForeignAPIGadgetRepo extends CachedGadgetRepo {
1011 /**
@@ -13,7 +14,7 @@
1415 */
1516 const VERSION = '1.0';
1617
17 - protected $source, $apiURL;
 18+ protected $source, $apiURL, $cacheTimeout = 600;
1819
1920 /**
2021 * Constructor.
@@ -25,6 +26,9 @@
2627
2728 $this->source = $options['source'];
2829 $this->apiURL = $wgResourceLoaderSources[$this->source]['apiScript'];
 30+ if ( isset( $options['cacheTimeout'] ) ) {
 31+ $this->cacheTimeout = $options['cacheTimeout'];
 32+ }
2933 }
3034
3135 /*** Protected methods inherited from CachedGadgetRepo ***/
@@ -62,8 +66,7 @@
6367 }
6468
6569 protected function getCacheExpiry( $id ) {
66 - global $wgGadgetsForeignCacheTimeout;
67 - return $wgGadgetsForeignCacheTimeout;
 70+ return $this->cacheTimeout;
6871 }
6972
7073 /*** Protected methods ***/

Sign-offs

UserFlagDate
Krinkleinspected22:37, 13 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102412[RL2] Set expiry times for cached gadget data. Expiry times are determined by...catrope17:07, 8 November 2011

Status & tagging log