mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
fix: remove unnecessary calls to purgeCache (#3502)
This commit is contained in:
parent
965d7d44c5
commit
5e22459eb6
7 changed files with 22 additions and 19 deletions
|
@ -91,8 +91,9 @@ class DisplayAction implements ActionInterface
|
|||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache->setScope('');
|
||||
$cache->purgeCache(86400);
|
||||
$cache->setKey($cache_params);
|
||||
// This cache purge will basically delete all cache items older than 24h, regardless of scope and key
|
||||
$cache->purgeCache(86400);
|
||||
|
||||
$items = [];
|
||||
$infos = [];
|
||||
|
@ -215,7 +216,7 @@ class DisplayAction implements ActionInterface
|
|||
$cache = $cacheFactory->create();
|
||||
$cache->setScope('error_reporting');
|
||||
$cache->setkey([$bridgeName . '_' . $code]);
|
||||
$cache->purgeCache(86400);
|
||||
|
||||
if ($report = $cache->loadData()) {
|
||||
$report = Json::decode($report);
|
||||
$report['time'] = time();
|
||||
|
|
|
@ -48,7 +48,7 @@ class EZTVBridge extends BridgeAbstract
|
|||
public function collectData()
|
||||
{
|
||||
$eztv_uri = $this->getEztvUri();
|
||||
Debug::log($eztv_uri);
|
||||
Logger::debug($eztv_uri);
|
||||
$ids = explode(',', trim($this->getInput('ids')));
|
||||
foreach ($ids as $id) {
|
||||
$data = json_decode(getContents(sprintf('%s/api/get-torrents?imdb_id=%s', $eztv_uri, $id)));
|
||||
|
|
|
@ -223,10 +223,10 @@ EOD;
|
|||
CURLOPT_POSTFIELDS => json_encode($request)
|
||||
];
|
||||
|
||||
Debug::log("Sending GraphQL query:\n" . $query);
|
||||
Debug::log("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
|
||||
Logger::debug("Sending GraphQL query:\n" . $query);
|
||||
Logger::debug("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
|
||||
$response = json_decode(getContents('https://gql.twitch.tv/gql', $header, $opts));
|
||||
Debug::log("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));
|
||||
Logger::debug("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));
|
||||
|
||||
if (isset($response->errors)) {
|
||||
$messages = array_column($response->errors, 'message');
|
||||
|
|
|
@ -228,6 +228,7 @@ EOD
|
|||
|
||||
$cache->setScope('twitter');
|
||||
$cache->setKey(['cache']);
|
||||
// todo: inspect mtime instead of purging with 3h
|
||||
$cache->purgeCache(60 * 60 * 3);
|
||||
$api = new TwitterClient($cache);
|
||||
|
||||
|
|
|
@ -78,12 +78,19 @@ class FileCache implements CacheInterface
|
|||
);
|
||||
|
||||
foreach ($cacheIterator as $cacheFile) {
|
||||
if (in_array($cacheFile->getBasename(), ['.', '..', '.gitkeep'])) {
|
||||
$basename = $cacheFile->getBasename();
|
||||
$excluded = [
|
||||
'.' => true,
|
||||
'..' => true,
|
||||
'.gitkeep' => true,
|
||||
];
|
||||
if (isset($excluded[$basename])) {
|
||||
continue;
|
||||
} elseif ($cacheFile->isFile()) {
|
||||
if (filemtime($cacheFile->getPathname()) < time() - $seconds) {
|
||||
$filepath = $cacheFile->getPathname();
|
||||
if (filemtime($filepath) < time() - $seconds) {
|
||||
// todo: sometimes this file doesn't exists
|
||||
unlink($cacheFile->getPathname());
|
||||
unlink($filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ final class RssBridge
|
|||
$error = error_get_last();
|
||||
if ($error) {
|
||||
$message = sprintf(
|
||||
'Fatal Error %s: %s in %s line %s',
|
||||
'(shutdown) %s: %s in %s line %s',
|
||||
$error['type'],
|
||||
sanitize_root($error['message']),
|
||||
sanitize_root($error['file']),
|
||||
|
|
|
@ -103,7 +103,6 @@ function getContents(
|
|||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache->setScope('server');
|
||||
$cache->purgeCache(86400);
|
||||
$cache->setKey([$url]);
|
||||
|
||||
// Snagged from https://github.com/lwthiker/curl-impersonate/blob/main/firefox/curl_ff102
|
||||
|
@ -424,10 +423,7 @@ function getSimpleHTMLDOMCached(
|
|||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache->setScope('pages');
|
||||
$cache->purgeCache(86400);
|
||||
|
||||
$params = [$url];
|
||||
$cache->setKey($params);
|
||||
$cache->setKey([$url]);
|
||||
|
||||
// Determine if cached file is within duration
|
||||
$time = $cache->getTime();
|
||||
|
@ -436,17 +432,15 @@ function getSimpleHTMLDOMCached(
|
|||
&& time() - $duration < $time
|
||||
&& !Debug::isEnabled()
|
||||
) {
|
||||
// Contents within duration and debug mode is disabled
|
||||
// Cache hit
|
||||
$content = $cache->loadData();
|
||||
} else {
|
||||
// Contents not within duration, or debug mode is enabled
|
||||
$content = getContents(
|
||||
$url,
|
||||
$header ?? [],
|
||||
$opts ?? []
|
||||
);
|
||||
// todo: fix bad if statement
|
||||
if ($content !== false) {
|
||||
if ($content) {
|
||||
$cache->saveData($content);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue