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)
1  2 
includes/filebackend/FileBackend.php
includes/filebackend/FileBackendStore.php

@@@ -242,9 -242,6 +242,9 @@@ abstract class FileBackend 
         *   - allowStale          : Don't require the latest available data.
         *                           This can increase performance for non-critical writes.
         *                           This has no effect unless the 'force' flag is set.
 +       *   - preserveCache       : Don't clear the process cache before checking files.
 +       *                           This should only be used if all entries in the process
 +       *                           cache were added after the files were already locked.
         *   - nonJournaled        : Don't log this operation batch in the file journal.
         *                           This limits the ability of recovery scripts.
         *   - parallelize         : Try to do operations in parallel when possible.
        }
  
        /**
-        * 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)
@@@ -989,9 -989,7 +989,9 @@@ abstract class FileBackendStore extend
                }
  
                // Clear any file cache entries (after locks acquired)
 -              $this->clearCache();
 +              if ( empty( $opts['preserveCache'] ) ) {
 +                      $this->clearCache();
 +              }
  
                // Load from the persistent file and container caches
                $this->primeFileCache( $performOps );
                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()
         */