cineverse-exi.page.dev - Optimasi KV Limit
Worker: lp-movie | Databased on: cineverse-db | Last Updated: Juli 2026
Worker lp-movie melakukan 9 parallel requests ke TMDB API untuk homepage saja.
Setiap request membutuhkan KV read/write, yang mengakibatkan limit harian (100K reads) cepat tercapai.
| Endpoint | KV Operations | Estimasi per 10K visitors |
|---|---|---|
| Homepage | 9 reads | 90,000 reads |
| Search | 2 reads | 20,000 reads |
| Genre Page | 1 read | 10,000 reads |
| Detail Movie | 1 read | 10,000 reads |
| Sitemap | 4 reads | 4,000 reads |
| Total | ~17 reads/page | 134,000+ reads |
| Komponen | Fungsi | Biaya | Status |
|---|---|---|---|
| Cache API | Cache response TMDB (1-2 jam) | GRATIS | ✅ Unlimited |
| D1 | Simpan metadata film (permanent) | GRATIS | 5M reads/hari |
| KV | Hanya untuk session/shortlink | LIMITED | 100K reads/hari |
| TMDB API | Source data (fetch saat cache miss) | GRATIS | 40 req/10s |
Limit: 100K reads/hari
Masalah: Cepat tercapai
Limit: ∞ (unlimited)
Keuntungan: Tidak ada limit
// lp-movie/src/index.js
export default {
async fetch(request, env) {
const url = new URL(request.url);
const cache = caches.default;
// 1. Cek Cache API dulu (gratis, cepat)
const cacheKey = new Request(url.toString(), request);
let response = await cache.match(cacheKey);
if (response) {
return addCacheHeader(response, 'HIT');
}
// 2. Cache miss - fetch dari TMDB
response = await fetchFromTMDB(url, env);
// 3. Simpan ke Cache API
await cache.put(cacheKey, response.clone());
// 4. Sync ke D1 untuk query (background)
waitUntil(syncToD1(response, env));
return addCacheHeader(response, 'MISS');
}
};
function addCacheHeader(response, status) {
const newResponse = new Response(response.body, response);
newResponse.headers.set('X-Cache-Status', status);
newResponse.headers.set('X-Cache-Date', new Date().toISOString());
return newResponse;
}
// Untuk response TMDB
{
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=1800'
}
// Penjelasan:
// - max-age=3600 → Fresh selama 1 jam
// - stale-while-revalidate=1800 → Setelah expired, masih serve
// stale sambil revalidasi di background (30 menit)
| Aspek | Sebelum (KV) | Sesudah (Cache API + D1) |
|---|---|---|
| Limit Harian | 100K reads | ∞ Unlimited |
| Storage | 6.8MB di KV | Cache otomatis + D1 |
| Biaya | Gratis | Gratis |
| Update Data | Manual TTL | Auto via Cache-Control |
| Query | Key-value only | SQL di D1 |
| Maintenance | Tinggi | Rendah |
Dengan arsitektur baru, Anda tidak akan lagi mengalami masalah KV limit. Semua data movie di-cache menggunakan Cache API (gratis), dan D1 digunakan untuk query kompleks.
Update worker lp-movie untuk menggunakan Cache API sebagai layer caching utama
Cleanup namespace yang tidak terpakai: ANALYTICS, CACHE, CACHE_KV, KV, cineverse-CACHE, dll
Buat worker terpisah untuk sync data TMDB ke D1 secara berkala
Gabungkan 4 shortlink namespace menjadi 1
Hapus workers yang sudah tidak dipakai (tes-*, lp-js-*, offer-*)
Gunakan curl untuk melihat header X-Cache-Status:
curl -I https://cineverse-exi.page.dev/
# Output yang diharapkan:
HTTP/2 200
content-type: text/html; charset=utf-8
cache-control: public, max-age=3600
x-cache-status: HIT ← Cache API serve
x-cache-date: 2026-07-27T10:00:00Z
| Header | Nilai | Arti |
|---|---|---|
X-Cache-Status |
HIT | Data dari Cache API (gratis) |
X-Cache-Status |
MISS | Fetch dari TMDB (akan di-cache) |
Cf-Cache-Status |
HIT | Cloudflare CDN cache |
Cf-Cache-Status |
DYNAMIC | Tidak di-cache (dynamic) |
Akses Cloudflare Dashboard untuk monitoring real-time:
Hapus 12 KV namespace kosong. Setup Cache API di worker lp-movie.
Deploy worker dengan Cache API. Test cache hit/miss behavior.
Buat worker sync TMDB → D1. Setup cron trigger untuk auto-sync.
Gabungkan 4 shortlink namespace menjadi 1. Update semua worker.
Full testing. Setup monitoring. Cleanup workers unused.
Arsitektur ini akan menyelesaikan masalah KV limit permanen. Cache API memberikan unlimited caching gratis, sementara D1 memberikan query SQL untuk data kompleks. Total biaya: $0 - $4/bulan.