From ef0701a97a748704142fdf1d34149586f02d468e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 6 Mar 2018 21:34:00 -0500 Subject: [PATCH] Fix wrong session expire set for custom duration --- src/Core/Cache.php | 55 ++++--------------------- src/Core/Cache/DatabaseCacheDriver.php | 2 +- src/Core/Cache/MemcacheCacheDriver.php | 2 +- src/Core/Cache/MemcachedCacheDriver.php | 2 +- 4 files changed, 11 insertions(+), 50 deletions(-) diff --git a/src/Core/Cache.php b/src/Core/Cache.php index a1b1ecb9c1..3f2edd2e20 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -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 * diff --git a/src/Core/Cache/DatabaseCacheDriver.php b/src/Core/Cache/DatabaseCacheDriver.php index 9703208d7b..17ae310074 100644 --- a/src/Core/Cache/DatabaseCacheDriver.php +++ b/src/Core/Cache/DatabaseCacheDriver.php @@ -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() ]; diff --git a/src/Core/Cache/MemcacheCacheDriver.php b/src/Core/Cache/MemcacheCacheDriver.php index 03fc075f4b..563447ef1e 100644 --- a/src/Core/Cache/MemcacheCacheDriver.php +++ b/src/Core/Cache/MemcacheCacheDriver.php @@ -61,7 +61,7 @@ class MemcacheCacheDriver extends BaseObject implements ICacheDriver self::getApp()->get_hostname() . ":" . $key, serialize($value), MEMCACHE_COMPRESSED, - Cache::duration($duration) + time() + $duration ); } diff --git a/src/Core/Cache/MemcachedCacheDriver.php b/src/Core/Cache/MemcachedCacheDriver.php index 8f1752cbed..1a8bdc9503 100644 --- a/src/Core/Cache/MemcachedCacheDriver.php +++ b/src/Core/Cache/MemcachedCacheDriver.php @@ -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 ); }