https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:00 PM
    That's why you see DYNAMIC.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:00 PM
    If you want to cache I think you need to use the Cache API? Let me confirm.
  • s

    Stew

    04/09/2022, 4:04 PM
    I did want this behind the general CDN cache, mainly so I can use tiered cache and get more hits (at the cost of some latency over edge caching). I know functions are just workers, but they don't run at the same workers stage as normal workers, pages is effectively an 'origin'.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:04 PM
    Pages itself is like an origin, yeah. But do you actually see the Function requests being cached?
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:04 PM
    AFAIK that's impossible.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:05 PM
    Confirmed, you can't put the regular cache in front of Functions.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:05 PM
    You'll need to use the Cache API, same as Workers.
  • s

    Stew

    04/09/2022, 4:05 PM
    I'll ping you a URL as an example
  • s

    Stew

    04/09/2022, 4:06 PM
    That page just returns the current timestamp, and you'll see the 'age' response header increase and timestamp stay the same until it gets to 120, then it updates
  • s

    Stew

    04/09/2022, 4:08 PM
    I'm looking into the sveltekit cloudflare-adapter and maybe this actually handles the cache
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:09 PM
    Oh, yeah!
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:09 PM
    SvelteKit recently added the Cache API internally.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:09 PM
    So it'll do caching.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:09 PM
    I thought you were referring to vanilla Functions.
  • s

    Stew

    04/09/2022, 4:10 PM
    Oh no sorry, I only thought there to look and see if this was doing something funky.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:10 PM
    As for why the Clear Cache doesn't work, that's because that doesn't purge the Workers Cache API.
  • s

    Stew

    04/09/2022, 4:10 PM
    Yeah that makes sense, and the static assets like favicon are cached in the cdn cache because they're static files
  • s

    Stew

    04/09/2022, 4:12 PM
    So this brings me to the awkward scenario I was wanting to avoid, there's no way to globally purge the cache api is there? Every time you save to the cache api, it is only saving it in that particular edge location, so if you run delete in another edge location the others won't be affected
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:14 PM
    I don't believe so... no?
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:15 PM
    Oh, actually.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:15 PM
    Apparently the Cache API should be purged with Purge Everything.
  • s

    Stew

    04/09/2022, 4:16 PM
    Should it also be purged by purge using url? I imagine probably not
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:18 PM
    No idea.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:18 PM
    But Cache Invalidation might take a minute.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:18 PM
    Try setting the cache-control up really high, at like 3600, then try a purge?
  • s

    Stew

    04/09/2022, 4:22 PM
    It was 120, and I tried purging within a few seconds of it being added and didn't work. Purge everything isn't really a solution anyway, I was looking to do this method as a lot of my pages are created by end users, but are unlikely to change frequently so wanted to cache them and purge just when they were updated. If I purge everything each time then nothing will ever be cached on my site 😅
  • s

    Stew

    04/09/2022, 4:26 PM
    This is really such a shame though, not being able to use the CDN cache from pages makes things much more difficult, I might be better off hosting off platform so I can use the CDN cache for my dynamic pages, or I'll need to try and hook in KV as a cache that I can purge globally (more work/cost).
  • h

    Hazard

    04/09/2022, 4:31 PM
    Is there some environment variable to say whether its a dev env?
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:32 PM
    Unfortunately those variables are only available at build-time.
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 4:32 PM
    You'd need to create your own.
1...114115116...392Latest