diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-10-07 21:15:52 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-10-07 21:29:23 +0200 |
commit | 0c2b17c80f54027aaebbc43b8efb21fdaffe8d45 (patch) | |
tree | b3708ab19ca04336268ffb558c9000c9a7874700 /lib/private/App/InfoParser.php | |
parent | 67d3574bdfdc08ad5815b5034a7c2c2e35afb4c0 (diff) | |
download | nextcloud-server-0c2b17c80f54027aaebbc43b8efb21fdaffe8d45.tar.gz nextcloud-server-0c2b17c80f54027aaebbc43b8efb21fdaffe8d45.zip |
Cache AppInfo in Memory Cache if configured
This saves around 20ms on a bare-bone instance, on bigger ones more (depending on the number of installed apps).
See https://blackfire.io/profiles/compare/fc326ad3-100d-49b8-8ea9-8343240f53f3/graph
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private/App/InfoParser.php')
-rw-r--r-- | lib/private/App/InfoParser.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index 3c14fe7c0cf..fbeb932763e 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -1,6 +1,7 @@ <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. + * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch> * * @author Andreas Fischer <bantu@owncloud.com> * @author Christoph Wurst <christoph@owncloud.com> @@ -26,7 +27,18 @@ namespace OC\App; +use OCP\ICache; + class InfoParser { + /** @var \OCP\ICache|null */ + private $cache; + + /** + * @param ICache|null $cache + */ + public function __construct(ICache $cache = null) { + $this->cache = $cache; + } /** * @param string $file the xml file to be loaded @@ -37,6 +49,13 @@ class InfoParser { return null; } + if(!is_null($this->cache)) { + $fileCacheKey = $file . filemtime($file); + if ($cachedValue = $this->cache->get($fileCacheKey)) { + return json_decode($cachedValue, true); + } + } + libxml_use_internal_errors(true); $loadEntities = libxml_disable_entity_loader(false); $xml = simplexml_load_file($file); @@ -119,6 +138,10 @@ class InfoParser { if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { $array['background-jobs'] = $array['background-jobs']['job']; } + + if(!is_null($this->cache)) { + $this->cache->set($fileCacheKey, json_encode($array)); + } return $array; } |