From 35792ea06a932f464b5d326da017d23f39cd8444 Mon Sep 17 00:00:00 2001 From: Lars Bonczek Date: Thu, 4 Aug 2022 12:47:26 +0200 Subject: [PATCH] MDL-75379 core: Use non-static template cache --- lib/outputrenderers.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index c500982260e..ee9d10be564 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -75,6 +75,11 @@ class renderer_base { */ private $mustache; + /** + * @var array $templatecache The mustache template cache. + */ + protected $templatecache = array(); + /** * Return an instance of the mustache class. * @@ -174,7 +179,6 @@ class renderer_base { * @return string|boolean */ public function render_from_template($templatename, $context) { - static $templatecache = array(); $mustache = $this->get_mustache(); try { @@ -190,12 +194,12 @@ class renderer_base { // e.g. aria attributes that only work with id attributes and must be // unique in a page. $mustache->addHelper('uniqid', new \core\output\mustache_uniqid_helper()); - if (isset($templatecache[$templatename])) { - $template = $templatecache[$templatename]; + if (isset($this->templatecache[$templatename])) { + $template = $this->templatecache[$templatename]; } else { try { $template = $mustache->loadTemplate($templatename); - $templatecache[$templatename] = $template; + $this->templatecache[$templatename] = $template; } catch (Mustache_Exception_UnknownTemplateException $e) { throw new moodle_exception('Unknown template: ' . $templatename); }