]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/database/class_BaseDatabaseWrapper.php
Renamed DatabaseResult to CachedDatabaseResult as it is actually "caching" the
[core.git] / inc / classes / main / database / class_BaseDatabaseWrapper.php
index cd785bb7ca341fca74e297b9a712df52f902aaab..77e530fd8e3fb64f73d1320d1b1a20ee05b6f271 100644 (file)
@@ -82,12 +82,18 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @return      void
         */
        protected function queryInsertDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = array()) {
-               // First get a key suitable for our cache and extend it with this class name
-               $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
-               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
+               // Default cache key is NULL
+               $cacheKey = NULL;
+
+               // Is cache enabled?
+               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+                       // First get a key suitable for our cache and extend it with this class name
+                       $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
+                       //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
+               } // END - if
 
                // Does this key exists in cache?
-               if ($this->cacheInstance->offsetExists($cacheKey)) {
+               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) && ($this->cacheInstance->offsetExists($cacheKey))) {
                        // Purge the cache
                        $this->cacheInstance->purgeOffset($cacheKey);
                } // END - if
@@ -104,12 +110,18 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @return      void
         */
        protected function queryUpdateDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = array()) {
-               // First get a key suitable for our cache and extend it with this class name
-               $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
-               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
+               // Init cache key
+               $cacheKey = NULL;
+
+               // Is cache enabled?
+               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+                       // First get a key suitable for our cache and extend it with this class name
+                       $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
+                       //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
+               } // END - if
 
                // Does this key exists in cache?
-               if ($this->cacheInstance->offsetExists($cacheKey)) {
+               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) && ($this->cacheInstance->offsetExists($cacheKey))) {
                        // Purge the cache
                        $this->cacheInstance->purgeOffset($cacheKey);
                } // END - if
@@ -182,7 +194,8 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                        }
                }
 
-               // Create an instance of a DatabaseResult class with the given result
+               // Create an instance of a CachedDatabaseResult class with the given result
+               // @TODO Minor: Update above comment to e.g. BaseDatabaseResult
                $resultInstance = ObjectFactory::createObjectByConfiguredName('database_result_class', array($result));
 
                // And return the instance
@@ -196,7 +209,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @param       $onlyKeys                       Only use these keys for a cache key
         * @return      $numRows                        Numbers of rows of database entries
         */
-       public function doSelectCountByCriteria (Criteria $criteriaInstance, $onlyKeys =  array()) {
+       public function doSelectCountByCriteria (Criteria $criteriaInstance, $onlyKeys = array()) {
                // Total numbers is -1 so we can distinglish between failed and valid queries
                $numRows = 0;