From 2524f394e2715ab702e80752b7896b198d626512 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 7 Jun 2012 12:50:43 -0700 Subject: [PATCH] [FileBackend] Fixed writer-populater cache race condition. * Set the keys to PURGED on purge. We already only treat array values in cache is valid. This means that if a process reads the file, it caches in the meantime, and then the process tries to cache the file, the stale version will not be cached. Change-Id: I7eb7b4529f8cea44b0d68c9149db4bcf100ac9d2 --- includes/filerepo/backend/FileBackendStore.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/filerepo/backend/FileBackendStore.php b/includes/filerepo/backend/FileBackendStore.php index f02724f2fa..2080639e10 100644 --- a/includes/filerepo/backend/FileBackendStore.php +++ b/includes/filerepo/backend/FileBackendStore.php @@ -1358,16 +1358,17 @@ abstract class FileBackendStore extends FileBackend { * @param $val mixed Information to cache */ final protected function setContainerCache( $container, $val ) { - $this->memCache->set( $this->containerCacheKey( $container ), $val, 14*86400 ); + $this->memCache->add( $this->containerCacheKey( $container ), $val, 14*86400 ); } /** - * Delete the cached info for a container + * Delete the cached info for a container. + * The cache key is salted for a while to prevent race conditions. * * @param $container string Resolved container name */ final protected function deleteContainerCache( $container ) { - if ( !$this->memCache->delete( $this->containerCacheKey( $container ) ) ) { + if ( !$this->memCache->set( $this->containerCacheKey( $container ), 'PURGED', 300 ) ) { trigger_error( "Unable to delete stat cache for container $container." ); } } @@ -1445,16 +1446,17 @@ abstract class FileBackendStore extends FileBackend { * @param $val mixed Information to cache */ final protected function setFileCache( $path, $val ) { - $this->memCache->set( $this->fileCacheKey( $path ), $val, 7*86400 ); + $this->memCache->add( $this->fileCacheKey( $path ), $val, 7*86400 ); } /** - * Delete the cached stat info for a file path + * Delete the cached stat info for a file path. + * The cache key is salted for a while to prevent race conditions. * * @param $path string Storage path */ final protected function deleteFileCache( $path ) { - if ( !$this->memCache->delete( $this->fileCacheKey( $path ) ) ) { + if ( !$this->memCache->set( $this->fileCacheKey( $path ), 'PURGED', 300 ) ) { trigger_error( "Unable to delete stat cache for file $path." ); } } -- 2.20.1