]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Configuration.php
Splitting ConfigCache & PConfigCache
[friendica.git] / src / Core / Config / Configuration.php
index ccb9abda8a67a5d143eca2309e0b7cd9fa040525..1489d91de04823104178c0f954f6d04e5249e212 100644 (file)
@@ -11,7 +11,7 @@ namespace Friendica\Core\Config;
 class Configuration
 {
        /**
-        * @var Cache\IConfigCache
+        * @var Cache\ConfigCache
         */
        private $configCache;
 
@@ -21,10 +21,10 @@ class Configuration
        private $configAdapter;
 
        /**
-        * @param Cache\IConfigCache     $configCache   The configuration cache (based on the config-files)
+        * @param Cache\ConfigCache     $configCache   The configuration cache (based on the config-files)
         * @param Adapter\IConfigAdapter $configAdapter The configuration DB-backend
         */
-       public function __construct(Cache\IConfigCache $configCache, Adapter\IConfigAdapter $configAdapter)
+       public function __construct(Cache\ConfigCache $configCache, Adapter\IConfigAdapter $configAdapter)
        {
                $this->configCache = $configCache;
                $this->configAdapter = $configAdapter;
@@ -35,7 +35,7 @@ class Configuration
        /**
         * Returns the Config Cache
         *
-        * @return Cache\IConfigCache
+        * @return Cache\ConfigCache
         */
        public function getCache()
        {
@@ -79,25 +79,23 @@ class Configuration
         */
        public function get($cat, $key, $default_value = null, $refresh = false)
        {
-               // Return the value of the cache if found and no refresh is forced
-               if (!$refresh && $this->configCache->has($cat, $key)) {
-                       return $this->configCache->get($cat, $key);
-               }
+               // if the value isn't loaded or refresh is needed, load it to the cache
+               if ($this->configAdapter->isConnected() &&
+                       (!$this->configAdapter->isLoaded($cat, $key) ||
+                       $refresh)) {
 
-               // if we don't find the value in the cache and the adapter isn't ready, return the default value
-               if (!$this->configAdapter->isConnected()) {
-                       return $default_value;
+                       $dbvalue = $this->configAdapter->get($cat, $key);
+
+                       if (isset($dbvalue)) {
+                               $this->configCache->set($cat, $key, $dbvalue);
+                               unset($dbvalue);
+                       }
                }
 
-               // load DB value to cache
-               $dbvalue = $this->configAdapter->get($cat, $key);
+               // use the config cache for return
+               $result = $this->configCache->get($cat, $key);
 
-               if ($dbvalue !== '!<unset>!') {
-                       $this->configCache->set($cat, $key, $dbvalue);
-                       return $dbvalue;
-               } else {
-                       return $default_value;
-               }
+               return (isset($result)) ? $result : $default_value;
        }
 
        /**