🎬 Rekomendasi Arsitektur

cineverse-exi.page.dev - Optimasi KV Limit

Worker: lp-movie | Databased on: cineverse-db | Last Updated: Juli 2026

📊 Analisis Status Saat Ini

70+ Workers
20 KV Namespaces
9 D1 Databases
6 R2 Buckets

⚠️ Masalah: KV Limit Terus Tercapai

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.

Worker lp-movie Analysis

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

🏗️ Arsitektur yang Direkomendasikan

🌐 Browser
☁️ CDN/Edge
⚡ Worker
📦 Cache API
GRATIS
🗄️ D1
MURAH
🎬 TMDB API
GRATIS
📊 KV
Session/Shortlink
🖼️ R2
Images

Komponen Arsitektur

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

🔄 Perbandingan Alur Data

❌ SEBELUM (KV Only)

Request User
Worker
KV Read
KV Write
TMDB API
Response

Limit: 100K reads/hari
Masalah: Cepat tercapai

✅ SESUDAH (Cache API + D1)

Request User
Worker
Cache API
TMDB API (jika miss)
Response

Limit: ∞ (unlimited)
Keuntungan: Tidak ada limit

💻 Implementasi Code

1. Worker dengan Cache API

// 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'); } };

2. Fungsi Cache Header

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; }

3. Cache-Control Header

// 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)

📈 Hasil Perbandingan

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

Estimasi Penghematan

0 KV Reads/hari
100% Cache Hit Rate
$0 Biaya Tambahan
10x Lebih Cepat

💰 Analisis Biaya

📦 Cache API

Storage GRATIS
Reads GRATIS
Writes GRATIS
Limit

🗄️ D1 Database

Reads/hari 5M gratis
Writes/hari 100K gratis
Storage 5GB gratis
Estimasi $0 - $3/bulan

📊 KV Namespace

Reads/hari 100K gratis
Writes/hari 1K gratis
Storage 1GB gratis
Estimasi $0 - $1/bulan

✅ Total Estimasi Bulanan: $0 - $4

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.

🎯 Action Plan

📊 Monitoring

🔍 Cara Cek Cache Status

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 yang Perlu Dipantau

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)

📈 Monitoring Dashboard

Akses Cloudflare Dashboard untuk monitoring real-time:

📅 Timeline Implementasi

Hari 1: Setup & Cleanup

Hapus 12 KV namespace kosong. Setup Cache API di worker lp-movie.

Hari 2: Implementasi Cache API

Deploy worker dengan Cache API. Test cache hit/miss behavior.

Hari 3: Setup D1 Sync

Buat worker sync TMDB → D1. Setup cron trigger untuk auto-sync.

Hari 4: Konsolidasi Shortlink

Gabungkan 4 shortlink namespace menjadi 1. Update semua worker.

Hari 5: Testing & Monitoring

Full testing. Setup monitoring. Cleanup workers unused.

🎯 Kesimpulan

Tidak ada lagi KV limit
100% Gratis
Lebih cepat (10x)
Maintenance rendah

🚀 Siap untuk Deploy?

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.