From 93e54ecfce5343ed9a1680d0d3bf371ff7e723ac Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 15 Jul 2015 23:17:53 +0200 Subject: [PATCH] Build a caching repository decorator for settings --- .../Settings/CachedSettingsRepository.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 framework/core/src/Core/Settings/CachedSettingsRepository.php diff --git a/framework/core/src/Core/Settings/CachedSettingsRepository.php b/framework/core/src/Core/Settings/CachedSettingsRepository.php new file mode 100644 index 000000000..0f5cb3c8f --- /dev/null +++ b/framework/core/src/Core/Settings/CachedSettingsRepository.php @@ -0,0 +1,45 @@ +inner = $inner; + } + + public function all() + { + if (!$this->isCached) { + $this->cache = $this->inner->all(); + $this->isCached = true; + } + + return $this->cache; + } + + public function get($key, $default = null) + { + if (array_key_exists($key, $this->cache)) { + return $this->cache[$key]; + } else if (!$this->isCached) { + return array_get($this->all(), $key, $default); + } + + return $default; + } + + public function set($key, $value) + { + $this->cache[$key] = $value; + + $this->inner->set($key, $value); + } +}