From 79910f36d47270e802e9ff3a36b4f10b5f1fa686 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 14 Apr 2013 13:32:34 -0700 Subject: [PATCH] [FileBackend] Made stat cache factor in last-modified time. * This should lesson the chance of consistency problems if there is any memcached flapping. * Also cleaned up some documentation. Change-Id: I89401892c7e848fcff0b093eaa861dfe02387a5c --- includes/filebackend/FileBackendStore.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index 46ec177965..6d142b9828 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -1581,9 +1581,10 @@ abstract class FileBackendStore extends FileBackend { * Set the cached info for a container * * @param string $container Resolved container name - * @param $val mixed Information to cache + * @param array $val Information to cache + * @return void */ - final protected function setContainerCache( $container, $val ) { + final protected function setContainerCache( $container, array $val ) { $this->memCache->add( $this->containerCacheKey( $container ), $val, 14 * 86400 ); } @@ -1592,6 +1593,7 @@ abstract class FileBackendStore extends FileBackend { * The cache key is salted for a while to prevent race conditions. * * @param string $container Resolved container name + * @return void */ final protected function deleteContainerCache( $container ) { if ( !$this->memCache->set( $this->containerCacheKey( $container ), 'PURGED', 300 ) ) { @@ -1672,14 +1674,17 @@ abstract class FileBackendStore extends FileBackend { * salting for the case when a file is created at a path were there was none before. * * @param string $path Storage path - * @param $val mixed Information to cache + * @param array $val Stat information to cache + * @return void */ - final protected function setFileCache( $path, $val ) { + final protected function setFileCache( $path, array $val ) { $path = FileBackend::normalizeStoragePath( $path ); if ( $path === null ) { return; // invalid storage path } - $this->memCache->add( $this->fileCacheKey( $path ), $val, 7 * 86400 ); + $age = time() - wfTimestamp( TS_UNIX, $val['mtime'] ); + $ttl = min( 7 * 86400, max( 300, floor( .1 * $age ) ) ); + $this->memCache->add( $this->fileCacheKey( $path ), $val, $ttl ); } /** @@ -1689,6 +1694,7 @@ abstract class FileBackendStore extends FileBackend { * a file is created at a path were there was none before. * * @param string $path Storage path + * @return void */ final protected function deleteFileCache( $path ) { $path = FileBackend::normalizeStoragePath( $path ); -- 2.20.1