Laravel Cache Remember Forever if Truthy
I kept needing a cache method that would only store a value permanently if the result was truthy. For expensive operations that might return null or false, I wanted to keep trying until I got a real result, then cache that forever. The problem Laravel’s Cache::rememberForever() caches any result, including null/false values. Fairly often I want to cache successful results and keep retrying failed ones. The solution Add this macro to your AppServiceProvider boot method: ...