1
1
Fork 0

Merge pull request #4557 from MrPetovan/task/4518-add-memcached-support

[develop] Hotfix: Fix wrong session expire set for custom duration
This commit is contained in:
Michael Vogel 2018-03-07 08:10:28 +01:00 committed by GitHub
commit e2fd882134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 50 deletions

View file

@ -12,14 +12,14 @@ use Friendica\Core\Config;
*/
class Cache extends \Friendica\BaseObject
{
const MONTH = 0;
const WEEK = 1;
const DAY = 2;
const HOUR = 3;
const HALF_HOUR = 4;
const QUARTER_HOUR = 5;
const FIVE_MINUTES = 6;
const MINUTE = 7;
const MONTH = 2592000;
const WEEK = 604800;
const DAY = 86400;
const HOUR = 3600;
const HALF_HOUR = 1800;
const QUARTER_HOUR = 900;
const FIVE_MINUTES = 300;
const MINUTE = 60;
/**
* @var Cache\ICacheDriver
@ -45,45 +45,6 @@ class Cache extends \Friendica\BaseObject
}
}
/**
* @brief Return the duration for a given cache level
*
* @param integer $level Cache level
*
* @return integer The cache duration in seconds
*/
public static function duration($level)
{
switch ($level) {
case self::MONTH:
$seconds = 2592000;
break;
case self::WEEK:
$seconds = 604800;
break;
case self::DAY:
$seconds = 86400;
break;
case self::HOUR:
$seconds = 3600;
break;
case self::HALF_HOUR:
$seconds = 1800;
break;
case self::QUARTER_HOUR:
$seconds = 900;
break;
case self::FIVE_MINUTES:
$seconds = 300;
break;
case self::MINUTE:
default:
$seconds = 60;
break;
}
return $seconds;
}
/**
* Returns the current cache driver
*

View file

@ -37,7 +37,7 @@ class DatabaseCacheDriver implements ICacheDriver
{
$fields = [
'v' => serialize($value),
'expires' => DateTimeFormat::utc('now + ' . Cache::duration($duration) . ' seconds'),
'expires' => DateTimeFormat::utc('now + ' . $duration . ' seconds'),
'updated' => DateTimeFormat::utcNow()
];

View file

@ -61,7 +61,7 @@ class MemcacheCacheDriver extends BaseObject implements ICacheDriver
self::getApp()->get_hostname() . ":" . $key,
serialize($value),
MEMCACHE_COMPRESSED,
Cache::duration($duration)
time() + $duration
);
}

View file

@ -52,7 +52,7 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
return $this->memcached->set(
self::getApp()->get_hostname() . ":" . $key,
$value,
Cache::duration($duration)
time() + $duration
);
}