mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-07 00:56:34 +02:00
refactor: dont create multiple instances of the cache (#3504)
This commit is contained in:
@@ -415,9 +415,7 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
*/
|
||||
protected function loadCacheValue(string $key, $duration = null)
|
||||
{
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache = RssBridge::getCache();
|
||||
// Create class name without the namespace part
|
||||
$scope = $this->getShortName();
|
||||
$cache->setScope($scope);
|
||||
@@ -441,9 +439,7 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
*/
|
||||
protected function saveCacheValue(string $key, $value)
|
||||
{
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache = RssBridge::getCache();
|
||||
$scope = $this->getShortName();
|
||||
$cache->setScope($scope);
|
||||
$cache->setKey([$key]);
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
final class RssBridge
|
||||
{
|
||||
private static CacheInterface $cache;
|
||||
|
||||
public function main(array $argv = [])
|
||||
{
|
||||
if ($argv) {
|
||||
@@ -69,6 +71,10 @@ final class RssBridge
|
||||
// Consider: ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
|
||||
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
|
||||
|
||||
// Create cache
|
||||
$cacheFactory = new CacheFactory();
|
||||
self::setCache($cacheFactory->create());
|
||||
|
||||
if (Configuration::getConfig('authentication', 'enable')) {
|
||||
$authenticationMiddleware = new AuthenticationMiddleware();
|
||||
$authenticationMiddleware();
|
||||
@@ -98,4 +104,14 @@ final class RssBridge
|
||||
$response->send();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCache(): CacheInterface
|
||||
{
|
||||
return self::$cache;
|
||||
}
|
||||
|
||||
public static function setCache(CacheInterface $cache): void
|
||||
{
|
||||
self::$cache = $cache;
|
||||
}
|
||||
}
|
||||
|
@@ -99,9 +99,7 @@ function getContents(
|
||||
array $curlOptions = [],
|
||||
bool $returnFull = false
|
||||
) {
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache = RssBridge::getCache();
|
||||
$cache->setScope('server');
|
||||
$cache->setKey([$url]);
|
||||
|
||||
@@ -419,9 +417,7 @@ function getSimpleHTMLDOMCached(
|
||||
$defaultBRText = DEFAULT_BR_TEXT,
|
||||
$defaultSpanText = DEFAULT_SPAN_TEXT
|
||||
) {
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache = RssBridge::getCache();
|
||||
$cache->setScope('pages');
|
||||
$cache->setKey([$url]);
|
||||
|
||||
|
Reference in New Issue
Block a user