perbaikan cache website - #1711
Open
pandigresik wants to merge 2 commits into
Open
Conversation
Contributor
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Fix Cache Invalidation pada Website API
Description
Fix issue #1710 di mana data slide (dan data website lainnya seperti profil, medsos, navigasi, pengurus, dll) yang ditambahkan/dihapus/diupdate melalui admin panel tidak langsung tampil di halaman website. Akar masalahnya adalah
WebsiteController::index()menggunakanCache::remember()untuk caching response, namun tidak ada mekanisme invalidation cache ketika data berubah. Data tetap stale sampai cache expired (1 jam).Changes made:
WebsiteCacheObserveryang otomatis clear cachewebsite:apipada eventcreated,updated,deleteddi model-model yang berkontribusi ke data websiteWebsiteController::index()dariCache::remember()keCacheService::remember()agar cache key ter-track di tablecache_keystheme-api.website.cache_prefixdiconfig/theme-api.phpWebsiteCacheObserverdi 11 model: Slide, MediaSosial, Navigation, NavMenu, Pengurus, SinergiProgram, Event, Profil, DataUmum, MediaTerkait, SettingAplikasiAPI_CACHE_ENABLEDdanAPI_CACHE_DURATIONdi.env.exampleReason for change:
WebsiteControllercache response 1 jam tanpa clear saat data berubahImpact of change:
✅ Bug Fix: Data website otomatis update saat ada perubahan di admin panel
✅ UX: Admin tidak perlu manual clear cache lagi
✅ Consistency: Mengikuti pattern yang sudah ada (seperti
GaleriObserver,ArtikelChangedlistener)Related Issue
Steps to Reproduce
Before fix (problem):
After fix (solution):
Testing on related features:
Checklist
Technical Details
Technical Explanation
Akar masalah:
WebsiteController::index()menggunakanCache::remember($key, 3600, callback)yang menyimpan response API di cache selama 1 jam. Ketika admin mengubah data (slide, profil, medsos, dll), tidak ada kode yang clear cache ini. Sehingga request berikutnya ke website API masih membaca data lama dari cache.Solusi:
Membuat
WebsiteCacheObserveryang didaftarkan sebagai Eloquent Observer di semua model yang data nya ditampilkan di website. Observer ini akan clear cachewebsite:apisetiap kali model di-create, di-update, atau di-delete.Alur cache invalidation:
File changes detail
Baru:
app/Observers/WebsiteCacheObserver.php- Observer yang clear website cacheDiubah:
app/Http/Controllers/Api/Frontend/WebsiteController.php-Cache::remember()→CacheService::remember()dengan prefix trackingconfig/theme-api.php- Tambahwebsite.cache_prefixconfigapp/Models/Slide.php- RegisterWebsiteCacheObserverapp/Models/MediaSosial.php- RegisterWebsiteCacheObserverapp/Models/Navigation.php- RegisterWebsiteCacheObserverapp/Models/NavMenu.php- RegisterWebsiteCacheObserverapp/Models/Pengurus.php- RegisterWebsiteCacheObserverapp/Models/SinergiProgram.php- RegisterWebsiteCacheObserverapp/Models/Event.php- RegisterWebsiteCacheObserverapp/Models/Profil.php- RegisterWebsiteCacheObserver(additional ke observer yang sudah ada)app/Models/DataUmum.php- RegisterWebsiteCacheObserver(additional ke observer yang sudah ada)app/Models/MediaTerkait.php- RegisterWebsiteCacheObserver(additional ke observer yang sudah ada)app/Models/SettingAplikasi.php- RegisterWebsiteCacheObserver(additional ke observer yang sudah ada).env.example- Tambah API cache env varsConfiguration changes
Ditambahkan entry baru di
config/theme-api.php:Dependencies added
None
Testing
Manual Testing
Video
simplescreenrecorder-2026-08-20_10.38.47.mp4
Migration Guide
Not required
References
Additional notes: Observer didaftarkan di 11 model yang berkontribusi ke data website. Model yang sudah memiliki observer lain (Profil, DataUmum, MediaTerkait, SettingAplikasi) tetap mempertahankan observer lama dan menambahkan
WebsiteCacheObserversebagai observer tambahan. Pattern ini mengikuti convention yang sudah ada di codebase (sepertiGaleriObserver,ClearArtikelCacheListener).