From: Roland Haeder Date: Thu, 25 Dec 2014 11:41:39 +0000 (+0100) Subject: Prevent generating cache keys if no query caching is enabled. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c66a5c7ddf1ff65fe8fbf09840836ad6793b1598;p=core.git Prevent generating cache keys if no query caching is enabled. Signed-off-by: Roland Häder --- diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index cd785bb7..3155f823 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 diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index aaa524c8..7f23e2ad 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -536,12 +536,14 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackend { } // END - foreach // Is all found? + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: isFound=' . intval($isFound)); if ($isFound === TRUE) { // Shall we skip this entry? if ($searchInstance->getSkip() > 0) { // We shall skip some entries if ($skipFound < $searchInstance->getSkip()) { // Skip this entry + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Found entry, but skipping ...'); $skipFound++; break; } // END - if @@ -559,6 +561,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackend { } // END - foreach // Write the data to a local file + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Writing dataArray()=' . count($dataArray) . ' to ' . $dataFile . ' ...'); $this->writeDataArrayToFqfn($pathName . $dataFile, $dataArray); // Count found entries up