X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2FBlockCache.php;h=43b77a7db7b3a9115ea81a8d16f3b1c60203fd44;hb=d42c91a23cf7c59a3cc1cc88438d087ca0d8bf6b;hp=8b49a0142c13d356ada07769f4e822def93bc94f;hpb=5c81d06b63e4172dae5ebfa745b642e26530e202;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/BlockCache.php b/includes/BlockCache.php index 8b49a0142c..43b77a7db7 100644 --- a/includes/BlockCache.php +++ b/includes/BlockCache.php @@ -1,14 +1,19 @@ mData = array(); + # Selecting FOR UPDATE is a convenient way to serialise the memcached and DB operations, + # which is necessary even though we don't update the DB + if ( $wgUseMemCached ) { + Block::enumBlocks( 'wfBlockCacheInsert', '', EB_FOR_UPDATE ); + $wgMemc->set( $this->mMemcKey, $this->mData, 0 ); + } else { + Block::enumBlocks( 'wfBlockCacheInsert', '' ); + } + } + + # Load the cache from memcached or, if that's not possible, from the DB + function load() { global $wgUseMemCached, $wgMemc; if ( $this->mData === false) { - $saveMemc = false; # Try memcached if ( $wgUseMemCached ) { $this->mData = $wgMemc->get( $this->mMemcKey ); - if ( !$this->mData ) { - $saveMemc = true; - } } if ( !is_array( $this->mData ) ) { - # Load from DB - $this->mData = array(); - Block::enumBlocks( 'wfBlockCacheInsert', '' ); # Calls $this->insert() - } - - if ( $saveMemc ) { - $wgMemc->set( $this->mMemcKey, $this->mData, 0 ); + $this->loadFromDB(); } } } - function insert( &$block ) - { + # Add a block to the cache + function insert( &$block ) { if ( $block->mUser == 0 ) { $nb = $block->getNetworkBits(); $ipint = $block->getIntegerAddr(); @@ -62,9 +71,9 @@ class BlockCache $this->mData[$nb][$index] = 1; } } - - function get( $ip ) - { + + # Find out if a given IP address is blocked + function get( $ip ) { $this->load(); $ipint = ip2long( $ip ); $blocked = false; @@ -90,24 +99,14 @@ class BlockCache return $block; } - function clear() - { - global $wgUseMemCached, $wgMemc; - - $this->mData = false; - if ( $wgUseMemCached ) { - $wgMemc->delete( $this->mMemcKey ); - } - } - - function clearLocal() - { + # Clear the local cache + # There was once a clear() to clear memcached too, but I deleted it + function clearLocal() { $this->mData = false; } } -function wfBlockCacheInsert( $block, $tag ) -{ +function wfBlockCacheInsert( $block, $tag ) { global $wgBlockCache; $wgBlockCache->insert( $block ); }