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
* 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
// 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
}
* @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;
}
/**
// 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
} // 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
// 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));
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