11 KiB
Cache Blade Views System
Table of Contents / İçindekiler
- Overview / Genel Bakış
- Function Description / Fonksiyon Açıklaması
- Usage Examples / Kullanım Örnekleri
- Default Cache Views / Varsayılan Cache View'lar
- How It Works / Nasıl Çalışır
- Error Handling / Hata Yönetimi
- 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
- Format:
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
- Format:
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-cache→spool-listadmin-ajax.spool-area-release-no-cache→spool-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-cache→spool-listadmin-ajax.spool-area-release-no-cache→spool-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:
-
Spool List Cache:
- View:
admin-ajax.spool-list-no-cache - Cache Name:
spool-list - Purpose: Caches the spool list view for faster loading
- View:
-
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
- View:
Türkçe: Fonksiyon, özel view verilmediğinde otomatik olarak dispatch edilen iki varsayılan cache view'a sahiptir:
-
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
- View:
-
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
- View:
How It Works / Nasıl Çalışır
English:
-
Parameter Check: The function checks if
$cacheViewsis empty- If empty → uses
$defaultCacheViews - If not empty → uses only
$cacheViews(ignores defaults)
- If empty → uses
-
Duplicate Removal: If custom views are provided, duplicates are removed based on cache name (keeps the last occurrence)
-
Job Dispatch: For each cache view, a
CacheBladeViewJobis dispatched asynchronously -
Error Handling: If a job dispatch fails, the error is logged but doesn't break the main operation
Türkçe:
-
Parametre Kontrolü: Fonksiyon
$cacheViews'ın boş olup olmadığını kontrol eder- Boş ise →
$defaultCacheViewskullanılır - Boş değilse → sadece
$cacheViewskullanılır (varsayılanlar göz ardı edilir)
- Boş ise →
-
Tekrar Kaldırma: Özel view'lar verilirse, cache adına göre tekrarlar kaldırılır (son oluşum korunur)
-
Job Dispatch: Her cache view için,
CacheBladeViewJobasenkron olarak dispatch edilir -
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:
-
Use Default Views When Possible:
- If you're updating spool-related data, use
dispatchCacheBladeViews()without parameters - This ensures all relevant caches are refreshed
- If you're updating spool-related data, use
-
Use Custom Views for Specific Updates:
- When you only need to refresh specific caches, provide custom views
- This reduces unnecessary job processing
-
Call After Data Updates:
- Always call
dispatchCacheBladeViews()after updating data that affects cached views - This ensures users see the latest information
- Always call
-
Handle Errors Gracefully:
- The function already handles errors internally, but monitor logs for dispatch failures
- Consider retry mechanisms for critical cache updates
-
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:
-
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
- Spool ile ilgili verileri güncelliyorsanız, parametresiz
-
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
-
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
- Cache'lenmiş view'ları etkileyen verileri güncelledikten sonra her zaman
-
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
-
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
Related Files / İlgili Dosyalar
English:
app/Functions/cache-blade-views.php- Main function fileapp/Jobs/CacheBladeViewJob.php- Job class that handles view cachingresources/views/admin-ajax/spool-list-no-cache.blade.php- Default cache viewresources/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 viewresources/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.