mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-13 03:54:04 +02:00
refactor: move cache logic into the factory (#2884)
This commit is contained in:
@@ -407,7 +407,7 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
{
|
||||
$cacheFac = new CacheFactory();
|
||||
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache = $cacheFac->create();
|
||||
$cache->setScope(get_called_class());
|
||||
$cache->setKey($key);
|
||||
if ($cache->getTime() < time() - $duration) {
|
||||
@@ -426,7 +426,7 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
{
|
||||
$cacheFac = new CacheFactory();
|
||||
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache = $cacheFac->create();
|
||||
$cache->setScope(get_called_class());
|
||||
$cache->setKey($key);
|
||||
$cache->saveData($value);
|
||||
|
@@ -29,10 +29,11 @@ class CacheFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name The name of the cache e.g. "File", "Memcached" or "SQLite"
|
||||
* @param string|null $name The name of the cache e.g. "File", "Memcached" or "SQLite"
|
||||
*/
|
||||
public function create(string $name): CacheInterface
|
||||
public function create(string $name = null): CacheInterface
|
||||
{
|
||||
$name ??= Configuration::getConfig('cache', 'type');
|
||||
$name = $this->sanitizeCacheName($name) . 'Cache';
|
||||
|
||||
if (! preg_match('/^[A-Z][a-zA-Z0-9-]*$/', $name)) {
|
||||
|
@@ -70,7 +70,7 @@ function getContents(
|
||||
) {
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache = $cacheFactory->create();
|
||||
$cache->setScope('server');
|
||||
$cache->purgeCache(86400); // 24 hours (forced)
|
||||
$cache->setKey([$url]);
|
||||
@@ -319,7 +319,7 @@ function getSimpleHTMLDOMCached(
|
||||
// Initialize cache
|
||||
$cacheFac = new CacheFactory();
|
||||
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache = $cacheFac->create();
|
||||
$cache->setScope('pages');
|
||||
$cache->purgeCache(86400); // 24 hours (forced)
|
||||
|
||||
|
@@ -58,7 +58,7 @@ function logBridgeError($bridgeName, $code)
|
||||
{
|
||||
$cacheFac = new CacheFactory();
|
||||
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache = $cacheFac->create();
|
||||
$cache->setScope('error_reporting');
|
||||
$cache->setkey($bridgeName . '_' . $code);
|
||||
$cache->purgeCache(86400); // 24 hours
|
||||
|
Reference in New Issue
Block a user