Adding force to update routine

- Introduced Cache::NEVER Lock (never expiring lock)
- Force flag for dbstructure update
- Moving the business logic to central place in Update class
This commit is contained in:
Philipp Holzer 2018-10-29 10:16:07 +01:00
parent f2ec963b95
commit 270e817954
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
9 changed files with 141 additions and 104 deletions

View file

@ -40,7 +40,7 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
*/
public function get($key)
{
$cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
$cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, DateTimeFormat::utcNow()]);
if (DBA::isResult($cache)) {
$cached = $cache['v'];
@ -62,11 +62,19 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
*/
public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
{
$fields = [
'v' => serialize($value),
'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
'updated' => DateTimeFormat::utcNow()
];
if ($ttl > 0) {
$fields = [
'v' => serialize($value),
'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
'updated' => DateTimeFormat::utcNow()
];
} else {
$fields = [
'v' => serialize($value),
'expires' => -1,
'updated' => DateTimeFormat::utcNow()
];
}
return DBA::update('cache', $fields, ['k' => $key], true);
}

View file

@ -34,7 +34,7 @@ interface ICacheDriver
*
* @param string $key The cache key
* @param mixed $value The value to store
* @param integer $ttl The cache lifespan, must be one of the Cache constants
* @param integer $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*/

View file

@ -28,7 +28,7 @@ interface IMemoryCacheDriver extends ICacheDriver
* @param string $key The cache key
* @param mixed $oldValue The old value we know from the cache
* @param mixed $newValue The new value we want to set
* @param int $ttl The cache lifespan, must be one of the Cache constants
* @param int $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*/