ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
LoaderCachingWrapper.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
8 
12 class LoaderCachingWrapper implements Loader
13 {
14  use LoaderHelper;
15 
19  private $loader;
20 
24  private $cache = array();
25 
26  public function __construct(Loader $loader)
27  {
28  $this->loader = $loader;
29  }
30 
34  public function getRendererFor(Component $component, array $contexts)
35  {
36  $key = $this->getCacheKey($component, $contexts);
37  if (isset($this->cache[$key])) {
38  return $this->cache[$key];
39  }
40  $renderer = $this->loader->getRendererFor($component, $contexts);
41  $this->cache[$key] = $renderer;
42  return $renderer;
43  }
44 
52  protected function getCacheKey(Component $component, array $contexts)
53  {
54  return $component->getCanonicalName() . " " . implode("_", $this->getContextNames($contexts));
55  }
56 
60  public function getRendererFactoryFor(Component $component)
61  {
62  return $this->loader->getRendererFactoryFor($component);
63  }
64 }
Caches renderers loaded by another loader.
getCanonicalName()
Get the canonical name of the component.
getCacheKey(Component $component, array $contexts)
Get a key for the cache.
Loads renderers for components.
Definition: Loader.php:12
getRendererFor(Component $component, array $contexts)
$key
Definition: croninfo.php:18