X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fcache%2FFileCacheBase.php;h=fb4253996f97e22aa384686901e6439c4a902275;hp=f2da08a3947f57e881bedfd0fc0967450a8e27cf;hb=54c93f1d384cd5accd2db2ebbb911e4d627c2980;hpb=b77e101acbba77fa80db8b166287bcdf81534e80 diff --git a/includes/cache/FileCacheBase.php b/includes/cache/FileCacheBase.php index f2da08a394..fb4253996f 100644 --- a/includes/cache/FileCacheBase.php +++ b/includes/cache/FileCacheBase.php @@ -179,9 +179,9 @@ abstract class FileCacheBase { * @return void */ public function clearCache() { - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); unlink( $this->cachePath() ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); $this->mCached = false; } @@ -230,31 +230,26 @@ abstract class FileCacheBase { */ public function incrMissesRecent( WebRequest $request ) { if ( mt_rand( 0, self::MISS_FACTOR - 1 ) == 0 ) { - $cache = ObjectCache::getLocalClusterInstance(); # Get a large IP range that should include the user even if that # person's IP address changes $ip = $request->getIP(); if ( !IP::isValid( $ip ) ) { return; } + $ip = IP::isIPv6( $ip ) ? IP::sanitizeRange( "$ip/32" ) : IP::sanitizeRange( "$ip/16" ); # Bail out if a request already came from this range... + $cache = ObjectCache::getLocalClusterInstance(); $key = $cache->makeKey( static::class, 'attempt', $this->mType, $this->mKey, $ip ); - if ( $cache->get( $key ) ) { + if ( !$cache->add( $key, 1, self::MISS_TTL_SEC ) ) { return; // possibly the same user } - $cache->set( $key, 1, self::MISS_TTL_SEC ); # Increment the number of cache misses... - $key = $this->cacheMissKey( $cache ); - if ( $cache->get( $key ) === false ) { - $cache->set( $key, 1, self::MISS_TTL_SEC ); - } else { - $cache->incr( $key ); - } + $cache->incrWithInit( $this->cacheMissKey( $cache ), self::MISS_TTL_SEC ); } }