From 343fd36671cc1c30fa707334fa7be03d183d12d3 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Wed, 19 Apr 2023 20:53:35 +0500 Subject: [PATCH] [core] Remove hardcoded maximum duration of 24 hours in loadCacheValue (#3355) --- bridges/BugzillaBridge.php | 2 +- bridges/WordPressMadaraBridge.php | 2 +- docs/05_Bridge_API/02_BridgeAbstract.md | 4 ++-- lib/BridgeAbstract.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bridges/BugzillaBridge.php b/bridges/BugzillaBridge.php index a7fc75b8..a5b2fd42 100644 --- a/bridges/BugzillaBridge.php +++ b/bridges/BugzillaBridge.php @@ -159,7 +159,7 @@ class BugzillaBridge extends BridgeAbstract protected function getUser($user) { // Check if the user endpoint is available - if ($this->loadCacheValue($this->instance . 'userEndpointClosed')) { + if ($this->loadCacheValue($this->instance . 'userEndpointClosed', 86400)) { return $user; } diff --git a/bridges/WordPressMadaraBridge.php b/bridges/WordPressMadaraBridge.php index 4325075c..c5ff54b5 100644 --- a/bridges/WordPressMadaraBridge.php +++ b/bridges/WordPressMadaraBridge.php @@ -117,7 +117,7 @@ The default URI shows the Madara demo page.'; protected function getMangaInfo($url) { $url_cache = 'TitleInfo_' . preg_replace('/[^\w]/', '.', rtrim($url, '/')); - $cache = $this->loadCacheValue($url_cache); + $cache = $this->loadCacheValue($url_cache, 86400); if (isset($cache)) { return $cache; } diff --git a/docs/05_Bridge_API/02_BridgeAbstract.md b/docs/05_Bridge_API/02_BridgeAbstract.md index 954e7732..120361be 100644 --- a/docs/05_Bridge_API/02_BridgeAbstract.md +++ b/docs/05_Bridge_API/02_BridgeAbstract.md @@ -489,11 +489,11 @@ public function collectData() Within the context of the current bridge, loads a value by key from cache. Optionally specifies the cache duration for the key. Returns `null` if the key doesn't exist or the value is expired. ```php -protected function loadCacheValue($key, $duration = 86400) +protected function loadCacheValue($key, $duration = null) ``` - `$key` - the name under which the value is stored in the cache. -- `$duration` - the maximum time in seconds after which the value expires. The default duration is 86400 (24 hours). +- `$duration` - the maximum time in seconds after which the value expires. Usage example: diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 8ebca650..322481e2 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -409,10 +409,10 @@ abstract class BridgeAbstract implements BridgeInterface * Loads a cached value for the specified key * * @param string $key Key name - * @param int $duration Cache duration (optional, default: 24 hours) + * @param int $duration Cache duration (optional) * @return mixed Cached value or null if the key doesn't exist or has expired */ - protected function loadCacheValue($key, int $duration = 86400) + protected function loadCacheValue($key, $duration = null) { $cacheFactory = new CacheFactory(); @@ -421,7 +421,7 @@ abstract class BridgeAbstract implements BridgeInterface $scope = $this->getShortName(); $cache->setScope($scope); $cache->setKey($key); - if ($cache->getTime() < time() - $duration) { + if ($duration && $cache->getTime() < time() - $duration) { return null; } return $cache->loadData();