function buildSidebar() {
global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
- $cache = ObjectCache::getMainWANInstance();
- $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
+ $that = $this;
+ $callback = function () use ( $that ) {
+ $bar = array();
+ $that->addToSidebar( $bar, 'sidebar' );
+ Hooks::run( 'SkinBuildSidebar', array( $that, &$bar ) );
- if ( $wgEnableSidebarCache ) {
- $cachedsidebar = $cache->get( $key );
- if ( $cachedsidebar ) {
- Hooks::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
-
- return $cachedsidebar;
- }
- }
+ return $bar;
+ };
- $bar = array();
- $this->addToSidebar( $bar, 'sidebar' );
-
- Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) );
if ( $wgEnableSidebarCache ) {
- $cache->set( $key, $bar, $wgSidebarCacheExpiry );
+ $cache = ObjectCache::getMainWANInstance();
+ $sidebar = $cache->getWithSetCallback(
+ $cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
+ $wgSidebarCacheExpiry,
+ $callback,
+ array( 'lockTSE' => 30 )
+ );
+ } else {
+ $sidebar = $callback();
}
- Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) );
+ // Apply post-processing to the cached value
+ Hooks::run( 'SidebarBeforeOutput', array( $this, &$sidebar ) );
- return $bar;
+ return $sidebar;
}
/**
* @param array $bar
* @param string $message
*/
- function addToSidebar( &$bar, $message ) {
+ public function addToSidebar( &$bar, $message ) {
$this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
}