Back

Laravel Performance Tip πŸš€
Stop hitting the cache twice! Many devs do `Cache::has()` before `Cache::get()` - but that doubles the work for the same key.
Benchmarks say it all:
- ⏱ Execution: 14ms β†’ 6ms
- 🧠 Memory: 47MB β†’ 43MB
- πŸ”‘ Cache calls: 2 β†’ 1
βœ… Fix: skip `has()`, just `get()` and check for null:

$value = Cache::get($key);
if ($value !== null) return $value;

Tiny tweak, huge impact under load. Full examples and results in the article!
dev.to/tegos/laravel-cache-tip-avoid-redundant-hasmissing-calls-4hi1

#Laravel #PHP #LaravelTips

β€’ β€’

48

β€’
β€’
  • No matching results...
  • Searching...

/ 1000

Poll Options