From: Aaron Schulz Date: Fri, 24 Aug 2012 06:17:16 +0000 (-0700) Subject: [FileBackend] Added preloadCache() so callers can trigger cache getMulti(). X-Git-Tag: 1.31.0-rc.0~22554^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/Category:Foo?a=commitdiff_plain;h=68808d7b9f238ddb1b5fb2aede4003a504885c91;p=lhc%2Fweb%2Fwiklou.git [FileBackend] Added preloadCache() so callers can trigger cache getMulti(). Change-Id: I2a30b4bfc16b4303abcb1f71206234dd2e0403af --- diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php index 4b707fc331..156097edff 100644 --- a/includes/filebackend/FileBackend.php +++ b/includes/filebackend/FileBackend.php @@ -899,7 +899,16 @@ abstract class FileBackend { } /** - * Invalidate any in-process file existence and property cache. + * Preload persistent file stat and property cache into in-process cache. + * This should be used when stat calls will be made on a known list of a many files. + * + * @param $paths Array Storage paths + * @return void + */ + public function preloadCache( array $paths ) {} + + /** + * Invalidate any in-process file stat and property cache. * If $paths is given, then only the cache for those files will be cleared. * * @param $paths Array Storage paths (optional) diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index 852a6538db..8dddf6a779 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -1106,6 +1106,20 @@ abstract class FileBackendStore extends FileBackend { return array(); } + /** + * @see FileBackend::preloadCache() + */ + final public function preloadCache( array $paths ) { + $fullConts = array(); // full container names + foreach ( $paths as $path ) { + list( $fullCont, $r, $s ) = $this->resolveStoragePath( $path ); + $fullConts[] = $fullCont; + } + // Load from the persistent file and container caches + $this->primeContainerCache( $fullConts ); + $this->primeFileCache( $paths ); + } + /** * @see FileBackend::clearCache() */ diff --git a/tests/phpunit/includes/filerepo/FileBackendTest.php b/tests/phpunit/includes/filerepo/FileBackendTest.php index c22a86760c..f9d78e5f4a 100644 --- a/tests/phpunit/includes/filerepo/FileBackendTest.php +++ b/tests/phpunit/includes/filerepo/FileBackendTest.php @@ -882,6 +882,20 @@ class FileBackendTest extends MediaWikiTestCase { "Correct file size of '$path'" ); $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10, "Correct file timestamp of '$path'" ); + + $this->backend->clearCache( array( $path ) ); + + $size = $this->backend->getFileSize( array( 'src' => $path ) ); + + $this->assertEquals( strlen( $content ), $size, + "Correct file size of '$path'" ); + + $this->backend->preloadCache( array( $path ) ); + + $size = $this->backend->getFileSize( array( 'src' => $path ) ); + + $this->assertEquals( strlen( $content ), $size, + "Correct file size of '$path'" ); } else { $size = $this->backend->getFileSize( array( 'src' => $path ) ); $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );