r107384 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107383‎ | r107384 | r107385 >
Date:15:18, 27 December 2011
Author:maxsem
Status:ok
Tags:
Comment:
Set up caching
Modified paths:
  • /trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php (modified) (history)
  • /trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php
@@ -40,10 +40,13 @@
4141
4242 ApiFormatFeedWrapper::setResult( $this->getResult(), $feedClass, $ourFeed['entries'] );
4343
 44+ // Cache stuff in squids
 45+ $this->getMain()->setCacheMode( 'public' );
 46+ $this->getMain()->setCacheMaxAge( FeaturedFeeds::getMaxAge() );
 47+
4448 wfProfileOut( __METHOD__ );
4549 }
4650
47 -
4851 public function getAllowedParams() {
4952 global $wgFeedClasses;
5053 $feedFormatNames = array_keys( $wgFeedClasses );
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php
@@ -24,9 +24,7 @@
2525
2626 if ( !$feeds ) {
2727 $feeds = self::getFeedsInternal( $langCode );
28 - // add 10 seconds to cater for time deviation between servers
29 - $expiry = self::todaysStart() + 24 * 3600 - wfTimestamp() + 10;
30 - $wgMemc->set( $key, $feeds, min( $expiry, 3600 ) );
 28+ $wgMemc->set( $key, $feeds, self::getMaxAge() );
3129 }
3230 $cache[$langCode] = $feeds;
3331 return $feeds;
@@ -168,4 +166,15 @@
169167 }
170168 return wfScript( 'api' ) . '?' . wfArrayToCGI( $options );
171169 }
 170+
 171+ /**
 172+ * Returns the number of seconds a feed should stay in cache
 173+ *
 174+ * @return int: Time in seconds
 175+ */
 176+ public static function getMaxAge() {
 177+ // add 10 seconds to cater for time deviation between servers
 178+ $expiry = self::todaysStart() + 24 * 3600 - wfTimestamp() + 10;
 179+ return min( $expiry, 3600 );
 180+ }
172181 }
\ No newline at end of file

Status & tagging log