mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-01 06:10:22 +02:00
fix: rewrite and improve caching (#3594)
This commit is contained in:
@@ -72,8 +72,30 @@ class RedditBridge extends BridgeAbstract
|
||||
]
|
||||
]
|
||||
];
|
||||
private CacheInterface $cache;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->cache = RssBridge::getCache();
|
||||
}
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
$cacheKey = 'reddit_rate_limit';
|
||||
if ($this->cache->get($cacheKey)) {
|
||||
throw new HttpException('429 Too Many Requests', 429);
|
||||
}
|
||||
try {
|
||||
$this->collectDataInternal();
|
||||
} catch (HttpException $e) {
|
||||
if ($e->getCode() === 429) {
|
||||
$this->cache->set($cacheKey, true, 60 * 16);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function collectDataInternal(): void
|
||||
{
|
||||
$user = false;
|
||||
$comments = false;
|
||||
|
Reference in New Issue
Block a user