mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-16 08:54:42 +02:00
refactor(cache): extract and encapsulate cache expiration logic (#3547)
* refactor(cache): extract and encapsulate cache expiration logic * fix: logic bug in getSimpleHTMLDOMCached * fix: silly me, index should of course be on the key column * silly me again, PRIMARY keys get index by default lol * comment out the delete portion in loadData * remove a few log statements * tweak twitter cache timeout
This commit is contained in:
parent
087e790ec1
commit
6254b8593e
12 changed files with 124 additions and 137 deletions
|
@ -409,26 +409,15 @@ abstract class BridgeAbstract implements BridgeInterface
|
|||
/**
|
||||
* Loads a cached value for the specified key
|
||||
*
|
||||
* @param int $duration Cache duration (optional)
|
||||
* @param int $timeout Cache duration (optional)
|
||||
* @return mixed Cached value or null if the key doesn't exist or has expired
|
||||
*/
|
||||
protected function loadCacheValue(string $key, $duration = null)
|
||||
protected function loadCacheValue(string $key, int $timeout = 86400)
|
||||
{
|
||||
$cache = RssBridge::getCache();
|
||||
// Create class name without the namespace part
|
||||
$scope = $this->getShortName();
|
||||
$cache->setScope($scope);
|
||||
$cache->setScope($this->getShortName());
|
||||
$cache->setKey([$key]);
|
||||
$timestamp = $cache->getTime();
|
||||
|
||||
if (
|
||||
$duration
|
||||
&& $timestamp
|
||||
&& $timestamp < time() - $duration
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return $cache->loadData();
|
||||
return $cache->loadData($timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -439,8 +428,7 @@ abstract class BridgeAbstract implements BridgeInterface
|
|||
protected function saveCacheValue(string $key, $value)
|
||||
{
|
||||
$cache = RssBridge::getCache();
|
||||
$scope = $this->getShortName();
|
||||
$cache->setScope($scope);
|
||||
$cache->setScope($this->getShortName());
|
||||
$cache->setKey([$key]);
|
||||
$cache->saveData($value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue