r102412 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102411‎ | r102412 | r102413 >
Date:17:07, 8 November 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
[RL2] Set expiry times for cached gadget data. Expiry times are determined by the repo and set to either zero or $wgGadgetsForeignCacheTimeout (=600 seconds by default)
Modified paths:
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/CachedGadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/ForeignAPIGadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -66,6 +66,18 @@
6767 */
6868 $wgGadgetEnableSharing = true;
6969
 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+
7082 /*** Setup ***/
7183
7284 define( 'NS_GADGET', 2300 );
Index: branches/RL2/extensions/Gadgets/backend/CachedGadgetRepo.php
@@ -48,6 +48,13 @@
4949 */
5050 abstract protected function getCacheKey( $id );
5151
 52+ /**
 53+ * Get the expiry time to use for caching a certain piece of data
 54+ * @param $id See getCacheKey()
 55+ * @return int Expiry time for memc, in seconds. If the expiry time is zero, the data is cached forever.
 56+ */
 57+ abstract protected function getCacheExpiry( $id );
 58+
5259 /*** Protected methods ***/
5360
5461 /**
@@ -76,7 +83,7 @@
7784 }
7885
7986 // Write to memc
80 - $wgMemc->set( $this->getCacheKey( $id ), $toCache );
 87+ $wgMemc->set( $this->getCacheKey( $id ), $toCache, $this->getCacheExpiry( $id ) );
8188 // Clear the gadget names array in memc so it'll be regenerated later
8289 $wgMemc->delete( $this->getCacheKey( null ) );
8390 }
@@ -129,11 +136,11 @@
130137 // array_fill() and array_combine() don't like empty arrays
131138 $toCache = array();
132139 }
133 - $wgMemc->set( $key, $toCache );
 140+ $wgMemc->set( $key, $toCache, $this->getCacheExpiry( null ) );
134141
135142 // Now that we have the data for every gadget, let's refresh those cache entries too
136143 foreach ( $this->data as $id => $gadgetData ) {
137 - $wgMemc->set( $this->getCacheKey( $id ), $gadgetData );
 144+ $wgMemc->set( $this->getCacheKey( $id ), $gadgetData, $this->getCacheExpiry( $id ) );
138145 }
139146
140147 $this->idsLoaded = true;
@@ -190,7 +197,7 @@
191198 $this->data[$id] = $data;
192199 }
193200 // Save to memc
194 - $wgMemc->set( $key, $data );
 201+ $wgMemc->set( $key, $data, $this->getCacheExpiry( $id ) );
195202
196203 return $data;
197204 }
Index: branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php
@@ -28,6 +28,13 @@
2929 }
3030 }
3131
 32+ protected function getCacheExpiry( $id ) {
 33+ // We're dealing with metadata for local gadgets, and we have
 34+ // full control over cache invalidation.
 35+ // So cache forever
 36+ return 0;
 37+ }
 38+
3239 protected function loadAllData() {
3340 $query = $this->getLoadAllDataQuery();
3441 $dbr = $this->getDB();
Index: branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php
@@ -91,6 +91,18 @@
9292 }
9393 }
9494
 95+ protected function getCacheExpiry( $id ) {
 96+ global $wgGadgetsForeignCacheTimeout;
 97+ if ( $this->hasSharedCache ) {
 98+ // We're using the other wiki's local cache, and
 99+ // the other wiki will be handling invalidation.
 100+ // So cache forever.
 101+ return 0;
 102+ } else {
 103+ return $wgGadgetsForeignCacheTimeout;
 104+ }
 105+ }
 106+
95107 protected function getLoadAllDataQuery() {
96108 $query = parent::getLoadAllDataQuery();
97109 $query['conds']['gd_shared'] = 1;
Index: branches/RL2/extensions/Gadgets/backend/ForeignAPIGadgetRepo.php
@@ -61,6 +61,11 @@
6262 }
6363 }
6464
 65+ protected function getCacheExpiry( $id ) {
 66+ global $wgGadgetsForeignCacheTimeout;
 67+ return $wgGadgetsForeignCacheTimeout;
 68+ }
 69+
6570 /*** Protected methods ***/
6671
6772 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r102557[RL2] Per r102412 CR, make the cache timeout configurable per-repo. Also kill...catrope18:55, 9 November 2011

Comments

#Comment by Catrope (talk | contribs)   23:37, 8 November 2011

Per Krinkle, expiry time should be configurable per-repo. The default can be 600 and doesn't have to be in a global as far as I'm concerned.

Status & tagging log