From 8b8db6665ee30a6e655952c325d3df03c7fa9a46 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 16 Jan 2022 12:59:28 +0100 Subject: [PATCH] fix: store values after a missed hit (#236) --- src/Http/Middleware/TrustProxies.php | 7 +++++-- tests/Unit/Http/Middleware/TrustProxiesTest.php | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Http/Middleware/TrustProxies.php b/src/Http/Middleware/TrustProxies.php index 4dc7227..c7ad823 100644 --- a/src/Http/Middleware/TrustProxies.php +++ b/src/Http/Middleware/TrustProxies.php @@ -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) { diff --git a/tests/Unit/Http/Middleware/TrustProxiesTest.php b/tests/Unit/Http/Middleware/TrustProxiesTest.php index 275cd7a..a3236a1 100644 --- a/tests/Unit/Http/Middleware/TrustProxiesTest.php +++ b/tests/Unit/Http/Middleware/TrustProxiesTest.php @@ -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')); } }