Skip to content

Commit

Permalink
Cache the globals in memory (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin authored Sep 9, 2024
1 parent f0807e0 commit 10860cf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/ViewComposers/StatamicGlobalDataComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class StatamicGlobalDataComposer
{
protected $globals;

public function getGlobals()
{
return Cache::rememberForever('statamic-globals-'.Site::current()->handle(), function() {
Expand All @@ -28,8 +30,12 @@ public function getGlobals()

public function compose(View $view) : View
{
if(!isset($view->globals)) {
$view->with('globals', optionalDeep((object)$this->getGlobals()));
if (!$this->globals) {
$this->globals = optionalDeep((object)$this->getGlobals());
}

if (!isset($view->globals)) {
$view->with('globals', $this->globals);
}

return $view;
Expand Down

0 comments on commit 10860cf

Please sign in to comment.