Merge "[FileBackend] Added preloadCache() so callers can trigger cache getMulti()."
authorCatrope <roan.kattouw@gmail.com>
Wed, 29 Aug 2012 00:13:57 +0000 (00:13 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 29 Aug 2012 00:13:57 +0000 (00:13 +0000)
includes/filebackend/FileBackend.php
includes/filebackend/FileBackendStore.php
tests/phpunit/includes/filerepo/FileBackendTest.php

index daa8f22..cb2433a 100644 (file)
@@ -902,7 +902,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)
index 9311a90..9bec145 100644 (file)
@@ -1108,6 +1108,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()
         */
index c22a867..f9d78e5 100644 (file)
@@ -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 ) );