1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-08 09:36:39 +02:00

refactor(cache): extract and encapsulate cache expiration logic (#3547)

* refactor(cache): extract and encapsulate cache expiration logic

* fix: logic bug in getSimpleHTMLDOMCached

* fix: silly me, index should of course be on the key column

* silly me again, PRIMARY keys get index by default lol

* comment out the delete portion in loadData

* remove a few log statements

* tweak twitter cache timeout
This commit is contained in:
Dag
2023-07-19 05:05:49 +02:00
committed by GitHub
parent 087e790ec1
commit 6254b8593e
12 changed files with 124 additions and 137 deletions

View File

@@ -282,14 +282,10 @@ class SpotifyBridge extends BridgeAbstract
$cacheKey = sprintf('%s:%s', $this->getInput('clientid'), $this->getInput('clientsecret'));
$cache->setScope('SpotifyBridge');
$cache->setKey([$cacheKey]);
$time = null;
if ($cache->getTime()) {
$time = (new DateTime())->getTimestamp() - $cache->getTime();
}
if (!$cache->getTime() || $time >= 3600) {
// fetch token
$token = $cache->loadData(3600);
if ($token) {
$this->token = $token;
} else {
$basicAuth = base64_encode(sprintf('%s:%s', $this->getInput('clientid'), $this->getInput('clientsecret')));
$json = getContents('https://accounts.spotify.com/api/token', [
"Authorization: Basic $basicAuth"
@@ -298,10 +294,9 @@ class SpotifyBridge extends BridgeAbstract
]);
$data = Json::decode($json);
$this->token = $data['access_token'];
$cache->setScope('SpotifyBridge');
$cache->setKey([$cacheKey]);
$cache->saveData($this->token);
} else {
$this->token = $cache->loadData();
}
}