Files
citrus-cms/resources/views/guide/cache-blade-views.md
T
2026-04-28 21:15:09 +03:00

11 KiB
Raw Blame History

Cache Blade Views System

Table of Contents / İçindekiler

  1. Overview / Genel Bakış
  2. Function Description / Fonksiyon Açıklaması
  3. Usage Examples / Kullanım Örnekleri
  4. Default Cache Views / Varsayılan Cache View'lar
  5. How It Works / Nasıl Çalışır
  6. Error Handling / Hata Yönetimi
  7. Best Practices / En İyi Uygulamalar

Overview / Genel Bakış

English: The dispatchCacheBladeViews() function is a helper function that dispatches CacheBladeViewJob for specified Blade views. This system is used to refresh cached Blade views after data updates, ensuring that users see the most up-to-date information without manual cache clearing.

Türkçe: dispatchCacheBladeViews() fonksiyonu, belirtilen Blade view'ları için CacheBladeViewJob dispatch eden bir yardımcı fonksiyondur. Bu sistem, veri güncellemelerinden sonra önbelleğe alınmış Blade view'larını yenilemek için kullanılır ve kullanıcıların manuel cache temizleme yapmadan en güncel bilgileri görmesini sağlar.


Function Description / Fonksiyon Açıklaması

English:

function dispatchCacheBladeViews(array $cacheViews = [])

Parameters / Parametreler:

  • $cacheViews (array, optional): Array of cache views to dispatch
    • Format: [['view' => 'view.path', 'cache' => 'cache-name'], ...]
    • If provided, only these views will be dispatched (default views will be ignored)
    • If empty, default cache views will be dispatched

Return Value / Dönüş Değeri:

  • void - No return value

Türkçe:

function dispatchCacheBladeViews(array $cacheViews = [])

Parametreler:

  • $cacheViews (array, opsiyonel): Dispatch edilecek cache view'larının dizisi
    • Format: [['view' => 'view.path', 'cache' => 'cache-name'], ...]
    • Verilirse, sadece bu view'lar dispatch edilir (varsayılan view'lar göz ardı edilir)
    • Boş ise, varsayılan cache view'ları dispatch edilir

Dönüş Değeri:

  • void - Dönüş değeri yok

Usage Examples / Kullanım Örnekleri

Example 1: Using Default Cache Views / Varsayılan Cache View'ları Kullanma

English: When called without parameters, the function dispatches default cache views:

dispatchCacheBladeViews();

This will dispatch jobs for:

  • admin-ajax.spool-list-no-cachespool-list
  • admin-ajax.spool-area-release-no-cachespool-area-release

Türkçe: Parametre olmadan çağrıldığında, fonksiyon varsayılan cache view'larını dispatch eder:

dispatchCacheBladeViews();

Bu, şu job'ları dispatch eder:

  • admin-ajax.spool-list-no-cachespool-list
  • admin-ajax.spool-area-release-no-cachespool-area-release

Example 2: Using Custom Cache Views / Özel Cache View'ları Kullanma

English: When custom cache views are provided, only those views will be dispatched (default views are ignored):

dispatchCacheBladeViews([
    [
        'view' => 'admin-ajax.custom-view-no-cache',
        'cache' => 'custom-cache-name'
    ],
    [
        'view' => 'admin-ajax.another-view-no-cache',
        'cache' => 'another-cache-name'
    ]
]);

Türkçe: Özel cache view'ları verildiğinde, sadece bu view'lar dispatch edilir (varsayılan view'lar göz ardı edilir):

dispatchCacheBladeViews([
    [
        'view' => 'admin-ajax.custom-view-no-cache',
        'cache' => 'custom-cache-name'
    ],
    [
        'view' => 'admin-ajax.another-view-no-cache',
        'cache' => 'another-cache-name'
    ]
]);

Example 3: Real-World Usage / Gerçek Dünya Kullanımı

English: Common usage in rollback or update operations:

// After updating spool status
spoolStatusChanger($spoolId, $newStatus);

// Refresh cache views
dispatchCacheBladeViews();

Türkçe: Rollback veya güncelleme işlemlerinde yaygın kullanım:

// Spool durumu güncellendikten sonra
spoolStatusChanger($spoolId, $newStatus);

// Cache view'ları yenile
dispatchCacheBladeViews();

Default Cache Views / Varsayılan Cache View'lar

English: The function has two default cache views that are automatically dispatched when no custom views are provided:

  1. Spool List Cache:

    • View: admin-ajax.spool-list-no-cache
    • Cache Name: spool-list
    • Purpose: Caches the spool list view for faster loading
  2. Spool Area Release Cache:

    • View: admin-ajax.spool-area-release-no-cache
    • Cache Name: spool-area-release
    • Purpose: Caches the spool area release view for faster loading

Türkçe: Fonksiyon, özel view verilmediğinde otomatik olarak dispatch edilen iki varsayılan cache view'a sahiptir:

  1. Spool Listesi Cache:

    • View: admin-ajax.spool-list-no-cache
    • Cache Adı: spool-list
    • Amaç: Spool listesi view'ını daha hızlı yükleme için cache'ler
  2. Spool Alan Serbest Bırakma Cache:

    • View: admin-ajax.spool-area-release-no-cache
    • Cache Adı: spool-area-release
    • Amaç: Spool alan serbest bırakma view'ını daha hızlı yükleme için cache'ler

How It Works / Nasıl Çalışır

English:

  1. Parameter Check: The function checks if $cacheViews is empty

    • If empty → uses $defaultCacheViews
    • If not empty → uses only $cacheViews (ignores defaults)
  2. Duplicate Removal: If custom views are provided, duplicates are removed based on cache name (keeps the last occurrence)

  3. Job Dispatch: For each cache view, a CacheBladeViewJob is dispatched asynchronously

  4. Error Handling: If a job dispatch fails, the error is logged but doesn't break the main operation

Türkçe:

  1. Parametre Kontrolü: Fonksiyon $cacheViews'ın boş olup olmadığını kontrol eder

    • Boş ise → $defaultCacheViews kullanılır
    • Boş değilse → sadece $cacheViews kullanılır (varsayılanlar göz ardı edilir)
  2. Tekrar Kaldırma: Özel view'lar verilirse, cache adına göre tekrarlar kaldırılır (son oluşum korunur)

  3. Job Dispatch: Her cache view için, CacheBladeViewJob asenkron olarak dispatch edilir

  4. Hata Yönetimi: Bir job dispatch'i başarısız olursa, hata loglanır ancak ana işlem bozulmaz


Error Handling / Hata Yönetimi

English: The function uses Laravel's Log::error() to log any errors that occur during job dispatch:

try {
    CacheBladeViewJob::dispatch($cacheView['view'], $cacheView['cache']);
} catch (\Exception $e) {
    Log::error('Failed to dispatch CacheBladeViewJob', [
        'view' => $cacheView['view'],
        'cache' => $cacheView['cache'],
        'error' => $e->getMessage()
    ]);
}

Key Points:

  • Errors are logged but don't break the main operation
  • Each error includes view path, cache name, and error message
  • The function continues processing other cache views even if one fails

Türkçe: Fonksiyon, job dispatch sırasında oluşan hataları loglamak için Laravel'in Log::error() metodunu kullanır:

try {
    CacheBladeViewJob::dispatch($cacheView['view'], $cacheView['cache']);
} catch (\Exception $e) {
    Log::error('Failed to dispatch CacheBladeViewJob', [
        'view' => $cacheView['view'],
        'cache' => $cacheView['cache'],
        'error' => $e->getMessage()
    ]);
}

Önemli Noktalar:

  • Hatalar loglanır ancak ana işlemi bozmaz
  • Her hata, view yolu, cache adı ve hata mesajını içerir
  • Bir cache view başarısız olsa bile, fonksiyon diğer cache view'ları işlemeye devam eder

Best Practices / En İyi Uygulamalar

English:

  1. Use Default Views When Possible:

    • If you're updating spool-related data, use dispatchCacheBladeViews() without parameters
    • This ensures all relevant caches are refreshed
  2. Use Custom Views for Specific Updates:

    • When you only need to refresh specific caches, provide custom views
    • This reduces unnecessary job processing
  3. Call After Data Updates:

    • Always call dispatchCacheBladeViews() after updating data that affects cached views
    • This ensures users see the latest information
  4. Handle Errors Gracefully:

    • The function already handles errors internally, but monitor logs for dispatch failures
    • Consider retry mechanisms for critical cache updates
  5. Avoid Duplicate Cache Names:

    • When providing custom views, ensure unique cache names
    • Duplicates are automatically removed (last one wins), but it's better to avoid them

Türkçe:

  1. Mümkün Olduğunda Varsayılan View'ları Kullanın:

    • Spool ile ilgili verileri güncelliyorsanız, parametresiz dispatchCacheBladeViews() kullanın
    • Bu, ilgili tüm cache'lerin yenilenmesini sağlar
  2. Belirli Güncellemeler İçin Özel View'ları Kullanın:

    • Sadece belirli cache'leri yenilemeniz gerektiğinde, özel view'lar sağlayın
    • Bu, gereksiz job işlemeyi azaltır
  3. Veri Güncellemelerinden Sonra Çağırın:

    • Cache'lenmiş view'ları etkileyen verileri güncelledikten sonra her zaman dispatchCacheBladeViews() çağırın
    • Bu, kullanıcıların en güncel bilgileri görmesini sağlar
  4. Hataları Zarif Şekilde Yönetin:

    • Fonksiyon zaten hataları dahili olarak yönetir, ancak dispatch başarısızlıkları için logları izleyin
    • Kritik cache güncellemeleri için yeniden deneme mekanizmaları düşünün
  5. Tekrarlanan Cache Adlarından Kaçının:

    • Özel view'lar sağlarken, benzersiz cache adları sağlayın
    • Tekrarlar otomatik olarak kaldırılır (son olan kazanır), ancak bunlardan kaçınmak daha iyidir

English:

  • app/Functions/cache-blade-views.php - Main function file
  • app/Jobs/CacheBladeViewJob.php - Job class that handles view caching
  • resources/views/admin-ajax/spool-list-no-cache.blade.php - Default cache view
  • resources/views/admin-ajax/spool-area-release-no-cache.blade.php - Default cache view

Türkçe:

  • app/Functions/cache-blade-views.php - Ana fonksiyon dosyası
  • app/Jobs/CacheBladeViewJob.php - View cache'leme işlemini yöneten job sınıfı
  • resources/views/admin-ajax/spool-list-no-cache.blade.php - Varsayılan cache view
  • resources/views/admin-ajax/spool-area-release-no-cache.blade.php - Varsayılan cache view

Summary / Özet

English: The dispatchCacheBladeViews() function is a powerful helper for managing Blade view caching in the DevQMS system. It provides a simple interface for refreshing cached views after data updates, with built-in error handling and support for both default and custom cache views.

Türkçe: dispatchCacheBladeViews() fonksiyonu, DevQMS sisteminde Blade view cache yönetimi için güçlü bir yardımcıdır. Veri güncellemelerinden sonra cache'lenmiş view'ları yenilemek için basit bir arayüz sağlar, dahili hata yönetimi ve hem varsayılan hem de özel cache view'ları için destek içerir.