public function saveUsageCache()
{
if ($this->persistentPrefix && $this->usageCacheIsDirty) {
// we never save it in the cache, it is only in database use, otherwise every page it will save the full cache to the database
// instead of only the accessed keys
//\Cache::put($this->usageCacheTransKey, $this->usageCache, 60 * 24 * 365);
\Cache::put($this->usageCacheTransKey, [], 60 * 24 * 365);
$this->usageCacheIsDirty = false;
$ltm_translations = $this->getTranslationsTableName();
// now update the keys in the database
foreach ($this->usageCache as $group => $keys) {
$setKeys = "";
$resetKeys = "";
foreach ($keys as $key => $usage) {
if ($usage) {
if ($setKeys) {
$setKeys .= ',';
}
$setKeys .= "'{$key}'";
} else {
if ($resetKeys) {
$resetKeys .= ',';
}
$resetKeys .= "'{$key}'";
}
}
if ($setKeys) {
$this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET was_used = 1 WHERE was_used <> 1 AND (`group` = ? OR `group` LIKE ? OR `group` LIKE ?) AND `key` IN ({$setKeys})
SQL
, [$group, 'vnd:%.' . $group, 'wbn:%.' . $group]);
}
if ($resetKeys) {
$this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET was_used = 0 WHERE was_used <> 0 AND (`group` = ? OR `group` LIKE ? OR `group` LIKE ?) AND `key` IN ({$resetKeys})
SQL
, [$group, 'vnd:%.' . $group, 'wbn:%.' . $group]);
}
}
}
}