Skip to content

Commit

Permalink
fix: store values after a missed hit (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jan 16, 2022
1 parent e17029f commit 8b8db66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class TrustProxies extends Middleware
*/
protected function setTrustedProxyIpAddresses(Request $request)
{
$cachedProxies = Cache::get(Config::get('laravelcloudflare.cache'), function () {
return LaravelCloudflare::getProxies();
$cacheKey = Config::get('laravelcloudflare.cache');
$cachedProxies = Cache::get($cacheKey, function () use ($cacheKey) {
return tap(LaravelCloudflare::getProxies(), function ($proxies) use ($cacheKey) {
Cache::forever($cacheKey, $proxies);
});
});

if (is_array($cachedProxies) && count($cachedProxies) > 0) {
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Http/Middleware/TrustProxiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ public function it_load_trustproxies()
$proxies = $request->getTrustedProxies();

$this->assertEquals(['expect'], $proxies);
$this->assertEquals(['expect'], $this->app['cache']->get('cloudflare.proxies'));
}
}

0 comments on commit 8b8db66

Please sign in to comment.