X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fdatabase%2Fclass_BaseDatabaseWrapper.php;h=77e530fd8e3fb64f73d1320d1b1a20ee05b6f271;hb=36dfe2c7247a1e6460826b41ce2cc011bb2d4ef9;hp=cd785bb7ca341fca74e297b9a712df52f902aaab;hpb=b83fedb8c8f81ea7c003275030857800c9587206;p=core.git diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index cd785bb7..77e530fd 100644 --- a/inc/classes/main/database/class_BaseDatabaseWrapper.php +++ b/inc/classes/main/database/class_BaseDatabaseWrapper.php @@ -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;