Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2013-10-21 16:04:07 +0400
committerAndreas Fischer <bantu@owncloud.com>2013-10-22 13:17:15 +0400
commiteb6637682ec835d9ec50612b59637e8b9ff5f6f6 (patch)
tree1fdad7068899557208db792eb1b7ecefcfe736ff /lib/autoloader.php
parentcadd71ec8a02fc5619a9347109f9e588e13b3e3b (diff)
Inject memoryCache into Autoloader. Remove recursion-prevention hack.
Diffstat (limited to 'lib/autoloader.php')
-rw-r--r--lib/autoloader.php55
1 files changed, 28 insertions, 27 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php
index b5b58918372..b0dc8904098 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
- }
+ 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) {
+ $this->memoryCache = $memoryCache;
+ }
}