```yaml product: AlterLab title: Caching category: guides comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data." source_url: https://alterlab.io/docs/guides/caching ``` # Caching Reduce costs and improve performance by caching scrape results. Pay once, reuse many times. > Caching is **disabled by default**. You must explicitly enable it with `cache: true`. ## How Caching Works 1. **First Request** -- With `cache: true`, the page is scraped, result is stored, and you're charged normally 2. **Subsequent Requests** -- Within the TTL window, same URL requests return cached data instantly. Cache hits are **free** 3. **Cache Expiry** -- After TTL expires, the next request fetches fresh data and refreshes the cache ## Enabling Cache ```bash curl -X POST https://api.alterlab.io/api/v1/scrape \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://example.com/products", "cache": true }' ``` The response includes `"cached": true/false` and `"credits_used": 0` for cache hits. ## Cache TTL Set a custom time-to-live in seconds: ```json { "url": "https://example.com/products", "cache": true, "cache_ttl": 3600 } ``` Default TTL is 15 minutes (900 seconds). ## Force Refresh Bypass cache and fetch fresh content: ```json { "url": "https://example.com/products", "cache": true, "cache_force_refresh": true } ``` This fetches fresh content and updates the cached version. ## Cache Response Headers | Header | Values | Description | |--------|--------|-------------| | `X-Cache` | `HIT` / `MISS` | Whether result came from cache | | `X-Cache-TTL` | seconds | Remaining TTL for cached result | ## Best Practices 1. **Use caching for monitoring** -- If you scrape the same pages repeatedly, caching can reduce costs by 90%+ 2. **Set appropriate TTLs** -- Use shorter TTLs for frequently changing pages, longer for static content 3. **Force refresh strategically** -- Use when you know content has changed 4. **Combine with webhooks** -- Cache results from async jobs for quick retrieval