Skip to content

Commit

Permalink
Cache one instance for each page
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerdee committed Feb 27, 2020
1 parent efdbbdc commit 47b4beb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/MetaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MetaTags
{
public $tags;

protected static $instance = null;
protected static $instances = [];

protected $indentation;
protected $order;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function __construct(Page $page)
$this->data = A::merge($this->data, $templates[$page->template()->name()]);
}

static::$instance = $this;
static::$instances[$this->page->id()] = $this;
}

/**
Expand All @@ -69,9 +69,7 @@ public function __construct(Page $page)
*/
public static function instance($page)
{
return static::$instance = is_null(static::$instance)
? new static($page)
: static::$instance;
return static::$instances[$page->id()] ?? new static($page);
}

public function render($groups = null)
Expand Down

0 comments on commit 47b4beb

Please sign in to comment.