diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index 18992842..ba87586b 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -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(); diff --git a/bridges/EZTVBridge.php b/bridges/EZTVBridge.php index 63062e2d..a2db3ead 100644 --- a/bridges/EZTVBridge.php +++ b/bridges/EZTVBridge.php @@ -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))); diff --git a/bridges/TwitchBridge.php b/bridges/TwitchBridge.php index b8ff1c40..8976174a 100644 --- a/bridges/TwitchBridge.php +++ b/bridges/TwitchBridge.php @@ -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'); diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index 9191c184..381dad76 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -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); diff --git a/caches/FileCache.php b/caches/FileCache.php index adaf458c..6e8e702d 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -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); } } } diff --git a/lib/RssBridge.php b/lib/RssBridge.php index e6f1c9e4..1610e48d 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -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']), diff --git a/lib/contents.php b/lib/contents.php index 20e30025..b54bc9fe 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -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); } }