| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Block; |
| 4 |
|
| 5 |
use MediaWiki\User\UserIdentity; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class BlockCache { |
| 11 |
|
| 12 |
private $cache = []; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public function get( BlockCacheKey $key ) { |
| 23 |
$entry = $this->cache[$key->getPartialKey()] ?? null; |
| 24 |
if ( $entry === null ) { |
| 25 |
return null; |
| 26 |
} |
| 27 |
return $key->matchesStored( $entry->key ) ? $entry->block : null; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function set( BlockCacheKey $key, $value ) { |
| 38 |
$this->cache[$key->getPartialKey()] = new BlockCacheEntry( $key, $value ); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public function clearUser( UserIdentity $user ) { |
| 47 |
foreach ( $this->cache as $partialKey => $entry ) { |
| 48 |
if ( $entry->key->isUser( $user ) ) { |
| 49 |
unset( $this->cache[$partialKey] ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |