summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Staudacher <andy.st@gmail.com>2010-02-21 21:29:24 -0800
committerAndy Staudacher <andy.st@gmail.com>2010-02-28 13:51:18 -0800
commitfd94f4bec21a7deaa86d468da704a048d2be751e (patch)
tree37b9b407847b92e2cced7867d3b40f27df384de8
parenta19b97f8d637ead3a4b038bdbd975be8a7583c59 (diff)
Fix Kohana's internal cache for Gallery's usage pattern. Instead of deleting the whole find_files cache when ever include_paths (=core.modules) change, keep a separate find_files cache for each set of include_paths.
Benefits for Gallery: - There are about 3000 is_file() invocations for a photo / album page in a vanilla Gallery installation. These are mostly triggered by Kohana::find_file(). - Enabling internal_cache doesn't help at all (see explanation below). The number of is_file() invocations is about the same with or without this cache. - With this patch, more than 95% of these invocations are gone. The cache works as intended. Kohana's internal_cache for find_file wasn't working in Gallery because the cache would be emptied on each request after reading it from disk and before most lookups would run. 1. Bootstrap sets initial core.modules (= include path): forge, kohana23_compat, gallery. 2. Kohana::setup() loads find_file cache from disk. 3. Gallery loads list of active modules and themes, and updates the core.modules value (=include path), which forces the internal find_file cache to be empties (which makes sense). 4. Request processing starts, and thus 80+% of all Kohana::find_file() triggered is_file() invocations start off with an empty find_file cache. The patch doesn't have a significant impact on performance for Kohana applications which don't change their include paths at runtime (after Kohana::setup). And the patch should benefit all Kohana applications which have modules / extensions, i.e. which first need to bootstrap Kohana before they can load a list of all active modules from the database.
-rw-r--r--system/core/Kohana.php16
1 files changed, 5 insertions, 11 deletions
diff --git a/system/core/Kohana.php b/system/core/Kohana.php
index ae056d0e..f7f6b326 100644
--- a/system/core/Kohana.php
+++ b/system/core/Kohana.php
@@ -32,6 +32,7 @@ abstract class Kohana_Core {
// Include paths
protected static $include_paths;
+ protected static $include_paths_hash = '';
// Cache lifetime
protected static $cache_lifetime;
@@ -365,14 +366,7 @@ abstract class Kohana_Core {
// Add SYSPATH as the last path
Kohana::$include_paths[] = SYSPATH;
- // Clear cached include paths
- self::$internal_cache['find_file_paths'] = array();
- if ( ! isset(self::$write_cache['find_file_paths']))
- {
- // Write cache at shutdown
- self::$write_cache['find_file_paths'] = TRUE;
- }
-
+ Kohana::$include_paths_hash = md5(serialize(Kohana::$include_paths));
}
return Kohana::$include_paths;
@@ -766,8 +760,8 @@ abstract class Kohana_Core {
// Search path
$search = $directory.'/'.$filename.$ext;
- if (isset(Kohana::$internal_cache['find_file_paths'][$search]))
- return Kohana::$internal_cache['find_file_paths'][$search];
+ if (isset(Kohana::$internal_cache['find_file_paths'][Kohana::$include_paths_hash][$search]))
+ return Kohana::$internal_cache['find_file_paths'][Kohana::$include_paths_hash][$search];
// Load include paths
$paths = Kohana::$include_paths;
@@ -824,7 +818,7 @@ abstract class Kohana_Core {
Kohana::$write_cache['find_file_paths'] = TRUE;
}
- return Kohana::$internal_cache['find_file_paths'][$search] = $found;
+ return Kohana::$internal_cache['find_file_paths'][Kohana::$include_paths_hash][$search] = $found;
}
/**