Caching & Performance

Introduction

Feedframer uses edge caching via Cloudflare instead of rate limiting. Every API request is cached at the edge for 1 hour, making responses extremely fast (always under 200ms) while protecting against DDoS attacks and ensuring fair usage for all users.

How Edge Caching Works

When you make an API request:

  1. First Request (Cache Miss): Cloudflare fetches data from our servers and caches it at the edge
  2. Subsequent Requests (Cache Hit): Cloudflare serves the cached response instantly from the edge
  3. Cache Duration: Responses are cached for 1 hour (3600 seconds)
  4. Automatic Refresh: After 1 hour, the next request triggers a fresh fetch

This approach provides:

  • Blazing fast responses - Always under 200ms
  • 🛡️ DDoS protection - No rate limiting needed
  • 🌍 Global edge network - Served from locations worldwide
  • ♻️ Fresh data - Auto-refreshes every hour

Cache Headers

Every API response includes cache information headers:

HTTP/1.1 200 OK
Content-Type: application/json
Age: 1
Cache-Control: max-age=3600, public
CF-Cache-Status: HIT
Header Description Example Values
Age Seconds since response was cached 0, 1, 3599
Cache-Control Cache policy and max age max-age=3600, public
CF-Cache-Status Cache hit/miss status HIT, MISS, EXPIRED

Understanding Cache Status

CF-Cache-Status Values

  • HIT - Response served from cache (fastest)
  • MISS - Response fetched from origin server (first request)
  • EXPIRED - Cache expired, fetching fresh data
  • DYNAMIC - Response not eligible for caching
  • BYPASS - Cache bypassed (e.g., after purge)

Checking Cache Age

Use the Age header to see how stale the cached data is:

const response = await fetch('https://feedframer.com/api/v1/me?api_key=YOUR_API_KEY');

const age = parseInt(response.headers.get('Age') || '0');
const cacheStatus = response.headers.get('CF-Cache-Status');
const maxAge = 3600; // 1 hour

console.log('Cache status:', cacheStatus);
console.log('Data age:', age, 'seconds');
console.log('Time until refresh:', maxAge - age, 'seconds');

Example: Cache Freshness Checker

async function checkCacheFreshness(apiKey) {
  const response = await fetch(
    `https://feedframer.com/api/v1/me?api_key=${apiKey}&page[size]=1`
  );

  const age = parseInt(response.headers.get('Age') || '0');
  const cacheStatus = response.headers.get('CF-Cache-Status');
  const maxAge = 3600;
  const freshnessPercent = ((maxAge - age) / maxAge) * 100;

  return {
    cacheStatus,
    ageSeconds: age,
    ageMinutes: Math.floor(age / 60),
    freshForSeconds: maxAge - age,
    freshForMinutes: Math.floor((maxAge - age) / 60),
    freshnessPercent: freshnessPercent.toFixed(1) + '%'
  };
}

const status = await checkCacheFreshness('YOUR_API_KEY');
console.log(status);
// {
//   cacheStatus: 'HIT',
//   ageSeconds: 120,
//   ageMinutes: 2,
//   freshForSeconds: 3480,
//   freshForMinutes: 58,
//   freshnessPercent: '96.7%'
// }

Manual Cache Purging

Need fresh data immediately? You can manually purge the cache from your dashboard.

How to Purge Cache

  1. Go to your Dashboard
  2. Find the Instagram account you want to refresh
  3. Click the "Purge Cache" button
  4. Next API request will fetch fresh data

This is useful when:

  • You just posted new content on Instagram
  • You need the latest data immediately
  • Testing your integration

Note: After purging, the next request will be slower (fetching from origin) but subsequent requests will be fast again (served from cache).