Internal cache for the class to speed up retrieving plugins and themes

This commit is contained in:
Djamil Legato
2014-09-17 17:08:36 -07:00
parent 967202cbc3
commit aa9af76f02
2 changed files with 26 additions and 11 deletions

View File

@@ -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]);

View File

@@ -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]);