diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-11-01 16:35:34 +0400 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-11-01 16:35:34 +0400 |
commit | 06b42f97886f09ca9527a00e54741fcce511debc (patch) | |
tree | 2e565d2c4f629368547818e52ef71377ab8b238e /lib | |
parent | eb0ecaa13c7494aa38719e67e6416d1a09fbaeab (diff) | |
parent | c85cc13d1ab926e6b75728ff45b84f4a53a724af (diff) |
Merge pull request #5443 from owncloud/fix-autoloader-caching
Remove Autoloader Cache Hack. Do not use Cache on Install.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/autoloader.php | 49 | ||||
-rw-r--r-- | lib/base.php | 8 |
2 files changed, 33 insertions, 24 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php index b5b58918372..3451f799e18 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -16,6 +16,12 @@ class Autoloader { private $classPaths = array(); /** + * Optional low-latency memory cache for class to path mapping. + * @var \OC\Memcache\Cache + */ + protected $memoryCache; + + /** * Add a custom prefix to the autoloader * * @param string $prefix @@ -112,44 +118,39 @@ class Autoloader { * @param string $class * @return bool */ - protected $memoryCache = null; - protected $constructingMemoryCache = true; // hack to prevent recursion public function load($class) { - // Does this PHP have an in-memory cache? We cache the paths there - if ($this->constructingMemoryCache && !$this->memoryCache) { - $this->constructingMemoryCache = false; - try { - $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); - } catch(\Exception $ex) { - // no caching then - fine with me - } - } + $pathsToRequire = null; 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)) { + if (!is_array($pathsToRequire)) { + // No cache or cache miss $pathsToRequire = array(); - foreach ($paths as $path) { - if ($fullPath = stream_resolve_include_path($path)) { - require_once $fullPath; + foreach ($this->findClass($class) as $path) { + $fullPath = stream_resolve_include_path($path); + if ($fullPath) { $pathsToRequire[] = $fullPath; } } - // Save in our memory cache if ($this->memoryCache) { $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec } } + + foreach ($pathsToRequire as $fullPath) { + require_once $fullPath; + } + return false; } + + /** + * @brief Sets the optional low-latency cache for class to path mapping. + * @param \OC\Memcache\Cache $memoryCache Instance of memory cache. + */ + public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null) { + $this->memoryCache = $memoryCache; + } } diff --git a/lib/base.php b/lib/base.php index 69b01a44702..47064c103e7 100644 --- a/lib/base.php +++ b/lib/base.php @@ -437,6 +437,14 @@ class OC { } self::initPaths(); + if (OC_Config::getValue('instanceid', false)) { + // \OC\Memcache\Cache has a hidden dependency on + // OC_Util::getInstanceId() for namespacing. See #5409. + try { + self::$loader->setMemoryCache(\OC\Memcache\Factory::createLowLatency('Autoloader')); + } catch(\Exception $ex) { + } + } OC_Util::isSetLocaleWorking(); // set debug mode if an xdebug session is active |