From 02e0d115a13da117ce451006a299ee313bdbb514 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 15 Mar 2014 02:08:04 -0700 Subject: [PATCH] Tweaked "latest" handling of filebackend stat entries * Let "latest" stat entries override non "latest" so that future getFileStat() calls with the "latest" flag can actually have a cache hit. Change-Id: I1e9391039537d608b89773b4d51575e3b364a751 --- includes/filebackend/FileBackendStore.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index 2d8214edc5..2fd1bf66a7 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -1666,7 +1666,22 @@ abstract class FileBackendStore extends FileBackend { } $age = time() - wfTimestamp( TS_UNIX, $val['mtime'] ); $ttl = min( 7 * 86400, max( 300, floor( .1 * $age ) ) ); - $this->memCache->add( $this->fileCacheKey( $path ), $val, $ttl ); + $key = $this->fileCacheKey( $path ); + // Set the cache unless it is currently salted with the value "PURGED". + // Using add() handles this except it also is a no-op in that case where + // the current value is not "latest" but $val is, so use CAS in that case. + if ( !$this->memCache->add( $key, $val, $ttl ) && !empty( $val['latest'] ) ) { + $this->memCache->merge( + $key, + function( BagOStuff $cache, $key, $cValue ) use ( $val ) { + return ( is_array( $cValue ) && empty( $cValue['latest'] ) ) + ? $val // update the stat cache with the lastest info + : false; // do nothing (cache is salted or some error happened) + }, + $ttl, + 1 + ); + } } /** -- 2.20.1