Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -66,6 +66,18 @@ |
67 | 67 | */ |
68 | 68 | $wgGadgetEnableSharing = true; |
69 | 69 | |
| 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 | + |
70 | 82 | /*** Setup ***/ |
71 | 83 | |
72 | 84 | define( 'NS_GADGET', 2300 ); |
Index: branches/RL2/extensions/Gadgets/backend/CachedGadgetRepo.php |
— | — | @@ -48,6 +48,13 @@ |
49 | 49 | */ |
50 | 50 | abstract protected function getCacheKey( $id ); |
51 | 51 | |
| 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 | + |
52 | 59 | /*** Protected methods ***/ |
53 | 60 | |
54 | 61 | /** |
— | — | @@ -76,7 +83,7 @@ |
77 | 84 | } |
78 | 85 | |
79 | 86 | // Write to memc |
80 | | - $wgMemc->set( $this->getCacheKey( $id ), $toCache ); |
| 87 | + $wgMemc->set( $this->getCacheKey( $id ), $toCache, $this->getCacheExpiry( $id ) ); |
81 | 88 | // Clear the gadget names array in memc so it'll be regenerated later |
82 | 89 | $wgMemc->delete( $this->getCacheKey( null ) ); |
83 | 90 | } |
— | — | @@ -129,11 +136,11 @@ |
130 | 137 | // array_fill() and array_combine() don't like empty arrays |
131 | 138 | $toCache = array(); |
132 | 139 | } |
133 | | - $wgMemc->set( $key, $toCache ); |
| 140 | + $wgMemc->set( $key, $toCache, $this->getCacheExpiry( null ) ); |
134 | 141 | |
135 | 142 | // Now that we have the data for every gadget, let's refresh those cache entries too |
136 | 143 | foreach ( $this->data as $id => $gadgetData ) { |
137 | | - $wgMemc->set( $this->getCacheKey( $id ), $gadgetData ); |
| 144 | + $wgMemc->set( $this->getCacheKey( $id ), $gadgetData, $this->getCacheExpiry( $id ) ); |
138 | 145 | } |
139 | 146 | |
140 | 147 | $this->idsLoaded = true; |
— | — | @@ -190,7 +197,7 @@ |
191 | 198 | $this->data[$id] = $data; |
192 | 199 | } |
193 | 200 | // Save to memc |
194 | | - $wgMemc->set( $key, $data ); |
| 201 | + $wgMemc->set( $key, $data, $this->getCacheExpiry( $id ) ); |
195 | 202 | |
196 | 203 | return $data; |
197 | 204 | } |
Index: branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php |
— | — | @@ -28,6 +28,13 @@ |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
| 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 | + |
32 | 39 | protected function loadAllData() { |
33 | 40 | $query = $this->getLoadAllDataQuery(); |
34 | 41 | $dbr = $this->getDB(); |
Index: branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php |
— | — | @@ -91,6 +91,18 @@ |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
| 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 | + |
95 | 107 | protected function getLoadAllDataQuery() { |
96 | 108 | $query = parent::getLoadAllDataQuery(); |
97 | 109 | $query['conds']['gd_shared'] = 1; |
Index: branches/RL2/extensions/Gadgets/backend/ForeignAPIGadgetRepo.php |
— | — | @@ -61,6 +61,11 @@ |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
| 65 | + protected function getCacheExpiry( $id ) { |
| 66 | + global $wgGadgetsForeignCacheTimeout; |
| 67 | + return $wgGadgetsForeignCacheTimeout; |
| 68 | + } |
| 69 | + |
65 | 70 | /*** Protected methods ***/ |
66 | 71 | |
67 | 72 | /** |