diff options
author | Markus Goetz <markus@woboq.com> | 2013-08-17 18:01:37 +0400 |
---|---|---|
committer | Markus Goetz <markus@woboq.com> | 2013-08-18 14:29:43 +0400 |
commit | aba64a0b81853dd3153da708538dddc96bbe647d (patch) | |
tree | 4cbc1b284c2e19b62fff4fe3fde31d5a06596d48 /lib/autoloader.php | |
parent | 680ac48856a4fff2445f0be3707d846b46ae670c (diff) |
Class Auto Loader: Cache paths in APC
Using benchmark_single.php (from administration repo) I can
measure a speed improvement of 5% to 20% loading the /index.php
when logged in. (when using APC and php-fpm).
Diffstat (limited to 'lib/autoloader.php')
-rw-r--r-- | lib/autoloader.php | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php index 21170639092..01841f831be 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -111,15 +111,39 @@ class Autoloader { * @param string $class * @return bool */ + protected $memoryCache = null; + protected $constructingMemoryCache = true; // hack to prevent recursion public function load($class) { - $paths = $this->findClass($class); + // Does this PHP have an in-memory cache? We cache the paths there + if ($this->constructingMemoryCache && !$this->memoryCache) { + $this->constructingMemoryCache = false; + $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); + } + if ($this->memoryCache) { + $pathsToRequire = $this->memoryCache->get($class); + if (is_array($pathsToRequire)) { + foreach ($pathsToRequire as $path) { + require_once $path; + } + return false; + } + } + // Use the normal class loading path + $paths = $this->findClass($class); if (is_array($paths)) { + $pathsToRequire = array(); foreach ($paths as $path) { if ($fullPath = stream_resolve_include_path($path)) { require_once $fullPath; + $pathsToRequire[] = $fullPath; } } + + // Save in our memory cache + if ($this->memoryCache) { + $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec + } } return false; } |