Uygulamanız yavaş mı çalışıyor? Veritabanı sorguları performansınızı düşürüyor mu? Doğru caching stratejileriyle Laravel uygulamanızı 10 kat daha hızlı hale getirebilirsiniz! İşte Redis ve Memcached ile performans artırma rehberi:
✔️ Veri kalıcılığı (persistence)
✔️ Daha fazla veri türü (hash, set, sorted set)
✔️ Pub/Sub mesajlaşma
✔️ Lua scripting desteği
🚀 Kullanım Alanı: Karmaşık cache ihtiyaçları, oturum yönetimi, kuyruk sistemleri
✔️ Basit key-value store
✔️ Çok yüksek performans
✔️ Çoklu sunucu desteği
✔️ Daha az bellek kullanımı
🚀 Kullanım Alanı: Basit cache ihtiyaçları, statik içerik önbelleğe alma
# Redis için composer require predis/predis # Memcached için sudo apt-get install php-memcached
CACHE_DRIVER=redis # veya memcached # Redis özel ayarları REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379
// Cache'e veri yazma Cache::put('key', 'value', $seconds); // Cache'ten veri okuma $value = Cache::get('key'); // Cache'ten veri silme Cache::forget('key'); // Varsa cache'ten getir, yoksa oluştur $value = Cache::remember('users', 3600, function () { return DB::table('users')->get(); });
// Tüm kullanıcıları 1 saat cache'le $users = Cache::remember('users.all', 3600, function () { return User::all(); });
@cache('posts.index', ['posts' => $posts], 60) <!-- View içeriği --> @endcache
Route::get('/stats', function () { // ... })->middleware('cache.headers:public;max_age=2628000;etag');
Cache::tags(['people', 'authors'])->put('John', $john, $seconds); Cache::tags(['people', 'artists'])->put('Anne', $anne, $seconds); // Tag'a göre temizleme Cache::tags(['authors'])->flush();
SenaryoCache YokRedisMemcached10k DB sorgusu2.4s0.3s0.2sSayfa yükleme1.8s0.4s0.3sEşzamanlı istek12 req/s210 req/s230 req/s
Pro tip: Laravel Horizon kullanıyorsanız zaten Redis kurulu demektir, ekstra avantajlarından faydalanın! 🎯
Siz hangisini tercih ediyorsunuz? Yorumlarda deneyimlerinizi paylaşın! 👇
Bir sonraki yazımız: 🚀 [Laravel'de Localization: Çok Dilli Uygulama Geliştirme] - Global uygulamalar için ihtiyacınız olan her şey!**
#Laravel #Redis #Memcached #Performance #WebDevelopment ⚡