https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • e

    eryn

    01/04/2021, 7:54 PM
    > Since Cloudflare’s Workers can run before, and after the cache I'm a little confused by this page, it seems like all of the examples below only mention ways to run the worker before the Cloudflare cache. It mentions the browser cache, so is that what it means by after? Or can you actually run workers behind a CDN cache? (Meaning the worker only runs if the request isn't cached)
  • d

    davidbarratt

    01/04/2021, 7:55 PM
    the
    fetch()
    funciton is what goes to the cache (or origin if it's no in there)
  • d

    davidbarratt

    01/04/2021, 8:05 PM
    so before the function executes is before the cache, after it executes, is after the cache
  • d

    davidbarratt

    01/04/2021, 8:05 PM
    basically a worker is a middleware
  • e

    eryn

    01/04/2021, 8:06 PM
    I'm confused by that answer, I don't think it's really answering my question?
  • d

    davidbarratt

    01/04/2021, 8:07 PM
    I guess I don't understand your question
  • d

    davidbarratt

    01/04/2021, 8:07 PM
    > It mentions the browser cache, so is that what it means by after? No
  • d

    davidbarratt

    01/04/2021, 8:08 PM
    > Or can you actually run workers behind a CDN cache? Yes.
  • d

    davidbarratt

    01/04/2021, 8:08 PM
    -ish
  • d

    davidbarratt

    01/04/2021, 8:08 PM
    it's infront and behind the cache simulatniously
  • d

    davidbarratt

    01/04/2021, 8:08 PM
    because it's a middleware
  • e

    eryn

    01/04/2021, 8:08 PM
    The essence of the question is if it's possible to only invoke a worker if a cached response from that worker is not available
  • d

    davidbarratt

    01/04/2021, 8:08 PM
    no
  • e

    Electroid

    01/04/2021, 8:08 PM
    That paragraph is misleading, we'll need to adjust the language. Workers always run before cache. They can interact with the Cache API, but it still runs before cache.
  • d

    davidbarratt

    01/04/2021, 8:08 PM
    the worker always executes no matter way
  • d

    davidbarratt

    01/04/2021, 8:09 PM
    *no matter what
  • e

    eryn

    01/04/2021, 8:09 PM
    Okay, that's why I think it's confusing! Because the docs say "Since Cloudflare’s Workers can run before, and after the cache", but it seems like they can only run before the cache.
  • d

    davidbarratt

    01/04/2021, 8:09 PM
    well they run after in the sense that you can modify a response from the cache
  • d

    davidbarratt

    01/04/2021, 8:10 PM
    your question is really: can I prevent a worker from executing? and the answer is: no
  • f

    FlorianKoerner

    01/04/2021, 8:19 PM
    Workaround: Other CDN => Cloudflare Workers
  • f

    FlorianKoerner

    01/04/2021, 8:20 PM
    I use BunnyCDN to cache the answers from my workers.
  • d

    davidbarratt

    01/04/2021, 8:27 PM
    why do you need to cache it? like I'm struggling to understand what value it brings?
  • d

    davidbarratt

    01/04/2021, 8:28 PM
    like let's say it takes a long time to generate a response, you can use https://developers.cloudflare.com/workers/runtime-apis/cache to store that in the cache and try and match it on the next reqeust...
  • e

    eryn

    01/04/2021, 8:28 PM
    less invocations!
  • d

    davidbarratt

    01/04/2021, 8:28 PM
    why is the number of invocations a problem? they are.... really cheap
  • f

    FlorianKoerner

    01/04/2021, 8:29 PM
    My workers always produce the same results with the same inputs. And I have several million queries a day. A cache simply makes sense. This way I save 95% of the costs.
  • f

    FlorianKoerner

    01/04/2021, 8:29 PM
    $5 instead of $100 makes a difference
  • e

    eryn

    01/04/2021, 8:30 PM
    My analytics are currently broken so im not really sure how many I have lol
  • e

    eryn

    01/04/2021, 8:31 PM
    it's either 519k or 287k per day. maybe the first number is last 24 hours and the second number is today so far? not sure
  • e

    eryn

    01/04/2021, 8:32 PM
    I thought i saw something in the docs about KV automatic caching but now I can't find it
1...272829...2509Latest