]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php
Refacuring:
[core.git] / framework / main / classes / database / frontend / class_BaseDatabaseFrontend.php
index 0a5aba8d77490d4645449f0d5e9f9b400c27b0db..a555e956a139cc19250859e3934673e584713eb4 100644 (file)
@@ -9,6 +9,7 @@ use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
 use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Traits\Cache\CacheableTrait;
 
 /**
  * A generic database frontend
@@ -33,10 +34,8 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
-       /**
-        * Cache instance
-        */
-       private $cacheInstance = NULL;
+       // Load traits
+       use CacheableTrait;
 
        /**
         * Current table name to use
@@ -65,7 +64,7 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
                // Is the cache enabled?
                if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) {
                        // Set the new instance
-                       $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
+                       $this->setCacheInstance(ObjectFactory::createObjectByConfiguredName('cache_class'));
                } // END - if
        }
 
@@ -75,8 +74,8 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
         * @param       $tableName      Name of table name to set
         * @return      void
         */
-       protected final function setTableName ($tableName) {
-               $this->tableName = (string) $tableName;
+       protected final function setTableName (string $tableName) {
+               $this->tableName = $tableName;
        }
 
        /**
@@ -109,10 +108,10 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
 
                // Does this key exists in cache?
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-WRAPPER: cacheKey[%s]=%s', gettype($cacheKey), $cacheKey));
-               if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->cacheInstance->offsetExists($cacheKey))) {
+               if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->getCacheInstance()->offsetExists($cacheKey))) {
                        // Purge the cache
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-WRAPPER: Calling this->cacheInstance->purgeOffset(%s) ...', $cacheKey));
-                       $this->cacheInstance->purgeOffset($cacheKey);
+                       $this->getCacheInstance()->purgeOffset($cacheKey);
                } // END - if
 
                // Handle it over to the middleware
@@ -141,9 +140,9 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
                } // END - if
 
                // Does this key exists in cache?
-               if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->cacheInstance->offsetExists($cacheKey))) {
+               if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->getCacheInstance()->offsetExists($cacheKey))) {
                        // Purge the cache
-                       $this->cacheInstance->purgeOffset($cacheKey);
+                       $this->getCacheInstance()->purgeOffset($cacheKey);
                } // END - if
 
                // Handle it over to the middleware
@@ -190,10 +189,10 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
 
                // Does this key exists in cache?
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-WRAPPER: cacheKey[%s]=%s', gettype($cacheKey), $cacheKey));
-               if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->cacheInstance->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1))) {
+               if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->getCacheInstance()->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1))) {
                        // Then use this result
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-WRAPPER: Cache used for cacheKey=%s', $cacheKey));
-                       $result = $this->cacheInstance->offsetGet($cacheKey);
+                       $result = $this->getCacheInstance()->offsetGet($cacheKey);
                } else {
                        // Now it's time to ask the database layer for this select statement
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-WRAPPER: Quering database, cacheKey=%s ...', $cacheKey));
@@ -206,7 +205,7 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem {
                                if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) {
                                        // A valid result has returned from the database layer
                                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-WRAPPER: Setting cacheKey=%s with result()=%d entries', $cacheKey, count($result)));
-                                       $this->cacheInstance->offsetSet($cacheKey, $result);
+                                       $this->getCacheInstance()->offsetSet($cacheKey, $result);
                                } // END - if
                        } else {
                                // This invalid result must be wrapped