diff --git a/system/src/Grav/Common/GPM/Local/Packages.php b/system/src/Grav/Common/GPM/Local/Packages.php index 63a6d8a8f..4498e6895 100644 --- a/system/src/Grav/Common/GPM/Local/Packages.php +++ b/system/src/Grav/Common/GPM/Local/Packages.php @@ -7,14 +7,20 @@ class Packages extends Iterator { private $plugins; private $themes; + protected static $cache; public function __construct() { - $plugins = new Plugins(); - $themes = new Themes(); + // local cache to speed things up + if (!isset(self::$cache[__METHOD__])) { + self::$cache[__METHOD__] = [ + 'plugins' => new Plugins(), + 'themes' => new Themes() + ]; + } - $this->plugins = $plugins; - $this->themes = $themes; + $this->plugins = self::$cache[__METHOD__]['plugins']; + $this->themes = self::$cache[__METHOD__]['themes']; $this->append(['plugins' => $this->plugins]); $this->append(['themes' => $this->themes]); diff --git a/system/src/Grav/Common/GPM/Remote/Packages.php b/system/src/Grav/Common/GPM/Remote/Packages.php index 020f051f2..f78e9c67e 100644 --- a/system/src/Grav/Common/GPM/Remote/Packages.php +++ b/system/src/Grav/Common/GPM/Remote/Packages.php @@ -3,15 +3,24 @@ namespace Grav\Common\GPM\Remote; use Grav\Common\Iterator; -class Packages extends Iterator { - private $plugins, $themes; +class Packages extends Iterator +{ + private $plugins; + private $themes; + protected static $cache; - public function __construct($refresh = false, $callback = null) { - $plugins = new Plugins($refresh, $callback); - $themes = new Themes($refresh, $callback); + public function __construct($refresh = false, $callback = null) + { + // local cache to speed things up + if (!isset(self::$cache[__METHOD__])) { + self::$cache[__METHOD__] = [ + 'plugins' => new Plugins($refresh, $callback), + 'themes' => new Themes($refresh, $callback) + ]; + } - $this->plugins = $plugins->toArray(); - $this->themes = $themes->toArray(); + $this->plugins = self::$cache[__METHOD__]['plugins']->toArray(); + $this->themes = self::$cache[__METHOD__]['themes']->toArray(); $this->append(['plugins' => $this->plugins]); $this->append(['themes' => $this->themes]);