* @file
* @ingroup Cache
*/
+use Wikimedia\Assert\Assert;
/**
* Handles a simple LRU key/value map with a maximum number of entries
* @throws Exception When $maxCacheKeys is not an int or =< 0.
*/
public function __construct( $maxKeys ) {
- if ( !is_int( $maxKeys ) || $maxKeys < 1 ) {
- throw new Exception( __METHOD__ . " must be given an integer and >= 1" );
- }
+ Assert::parameterType( 'integer', $maxKeys, '$maxKeys' );
+ Assert::parameter( $maxKeys >= 1, '$maxKeys', 'must be >= 1' );
+
$this->maxCacheKeys = $maxKeys;
}
* @return bool
*/
public function has( $key ) {
- if ( is_string( $key ) || is_integer( $key ) ) {
- return array_key_exists( $key, $this->cache );
- }
- wfWarn( __METHOD__ . ": Key passed isn't a string or an integer.", 2 );
- return false;
+ return array_key_exists( $key, $this->cache );
}
/**