1
0
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:
Dag
2022-07-05 13:20:01 +02:00
committed by GitHub
parent 5b9b579652
commit 321ec7c8c1
10 changed files with 16 additions and 15 deletions

View File

@@ -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);

View File

@@ -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)) {

View File

@@ -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)

View File

@@ -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