Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    Smart Paywall Caching

    Industry-standard caching for instant paywall display and offline support

    Why Smart Caching?

    Instant Display
    Paywalls load in < 100ms from cache
    Offline Support
    Works without network connection
    Auto Updates
    Background updates when available
    80% Cost Savings
    Dramatic reduction in API calls

    How It Works

    1
    Cache First
    SDK checks its local cache first for instant display
    2
    Display Immediately
    Show cached paywall to user (< 100ms)
    3
    Background Version Check
    SDK checks server for newer versions without blocking UI
    4
    Silent Update
    If new version available, fetch and cache in background

    Web SDK Implementation

    TypeScript / JavaScript

    Basic Setup (Caching Enabled by Default)
    import BillDog from '@billdog.io/web';
    
    BillDog.configure({ apiKey: 'your_api_key' });
    
    // First call: Fetches from network + caches
    const paywall = await BillDog.fetchPaywall('premium');
    
    // Subsequent calls: Instant from cache (< 100ms)
    const paywallAgain = await BillDog.fetchPaywall('premium'); // ⚡
    Cache Configuration Defaults

    Caching is enabled by default. The cache settings in the Paywall Builder’s Cache panel are saved with the paywall but not sent to the SDKs yet, so these defaults apply. The effective CacheConfig has these fields:

    const cacheConfig = {
      enabled: true,                  // Default: true
      maxCacheAge: 604800000,         // 7 days
      preloadAssets: true,            // Default: true
      backgroundUpdateEnabled: true   // Default: true
    };
    Cache Management
    // Clear all paywall and survey caches
    await BillDog.clearCache();

    Configuration Reference

    OptionDefaultDescription
    enabledtrueEnable/disable caching system
    preloadAssetstrueDownload images during idle time
    maxCacheAge604800000Cache lifetime in milliseconds (7 days)
    backgroundUpdateEnabledtrueFetch new versions in background

    Performance Impact

    Load Time (Cached)
    From the local cache
    < 100ms ⚡
    Load Time (Network)
    Fresh fetch
    < 500ms
    API Call Reduction
    After cache warmed
    80%+ 💰
    Cache Hit Rate
    Target metric
    > 90% 📈

    Best Practices

    • ✓
      Keep caching enabled in production
      Provides better user experience and reduces costs
    • ✓
      Use background updates
      Ensures users always see fresh content without blocking UI
    • ✓
      Enable asset preloading
      Downloads images during idle time for seamless experience
    • !
      Clear cache for testing
      Call the SDK’s clearCache() on your test device (or reinstall the app) to fetch a newly published version. Clear All Cache in the Paywall Builder clears only your browser’s preview cache, not devices.
    • !
      Monitor cache hit rates
      Aim for > 90% cache hits for optimal performance

    Testing Your Implementation

    1. Test Cache Hit
    // First call - should fetch from network
    const paywall1 = await BillDog.fetchPaywall('premium');
    console.log('First call took:', /* measure time */);
    
    // Second call - should be instant from cache
    const paywall2 = await BillDog.fetchPaywall('premium');
    console.log('Second call took:', /* should be < 100ms */);
    2. Test Offline Mode
    // 1. Load paywall once to cache it
    await BillDog.fetchPaywall('premium');
    
    // 2. Go offline (disable network in DevTools)
    // 3. Reload page and fetch paywall again
    const offlinePaywall = await BillDog.fetchPaywall('premium');
    // Should work from cache! ✅

    Was this page helpful?

    Or rate this page:

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.