Another way to clear database cache

This commit is contained in:
slawkens 2024-01-27 19:27:25 +01:00
parent 3a58c8a6f9
commit 87df817eae
3 changed files with 25 additions and 7 deletions

View File

@ -74,7 +74,7 @@ if(ModelsFAQ::count() == 0) {
]);
}
clearCache();
$db->setClearCacheAfter(true);
$locale['step_finish_desc'] = str_replace('$ADMIN_PANEL$', generateLink(str_replace('tools/', '',ADMIN_URL), $locale['step_finish_admin_panel'], true), $locale['step_finish_desc']);
$locale['step_finish_desc'] = str_replace('$HOMEPAGE$', generateLink(str_replace('tools/', '', BASE_URL), $locale['step_finish_homepage'], true), $locale['step_finish_desc']);

View File

@ -1213,7 +1213,6 @@ function clearCache()
'towns', 'groups', 'vocations',
'visitors', 'views_counter', 'failed_logins',
'template_menus',
'database_tables', 'database_columns', 'database_checksum',
'last_kills',
'hooks', 'plugins_hooks', 'plugins_routes', 'plugins_settings', 'plugins_themes', 'plugins_commands',
'settings',
@ -1242,6 +1241,9 @@ function clearCache()
$cache->delete($item);
}
}
global $db;
$db->setClearCacheAfter(true);
}
deleteDirectory(CACHE . 'signatures', ['index.html'], true);

View File

@ -28,6 +28,8 @@ class OTS_DB_MySQL extends OTS_Base_DB
{
private $has_table_cache = array();
private $has_column_cache = array();
private $clearCacheAfter = false;
/**
* Creates database connection.
*
@ -96,7 +98,8 @@ class OTS_DB_MySQL extends OTS_Base_DB
}
global $config;
if(class_exists('Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) {
$cache = Cache::getInstance();
if($cache->enabled()) {
$tmp = null;
$need_revalidation = true;
if($cache->fetch('database_checksum', $tmp) && $tmp) {
@ -147,10 +150,18 @@ class OTS_DB_MySQL extends OTS_Base_DB
{
global $config;
if(class_exists('Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) {
$cache->set('database_tables', serialize($this->has_table_cache), 3600);
$cache->set('database_columns', serialize($this->has_column_cache), 3600);
$cache->set('database_checksum', serialize(sha1($config['database_host'] . '.' . $config['database_name'])), 3600);
$cache = Cache::getInstance();
if($cache->enabled()) {
if ($this->clearCacheAfter) {
$cache->delete('database_tables');
$cache->delete('database_columns');
$cache->delete('database_checksum');
}
else {
$cache->set('database_tables', serialize($this->has_table_cache), 3600);
$cache->set('database_columns', serialize($this->has_column_cache), 3600);
$cache->set('database_checksum', serialize(sha1($config['database_host'] . '.' . $config['database_name'])), 3600);
}
}
if($this->logged) {
@ -238,6 +249,11 @@ class OTS_DB_MySQL extends OTS_Base_DB
}
}
}
public function setClearCacheAfter($clearCache)
{
$this->clearCacheAfter = $clearCache;
}
}
/**#@-*/