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

    Deleted User

    03/09/2023, 1:19 AM
    It's showing the old one
  • k

    kian

    03/09/2023, 1:19 AM
    The resource you `fetch()`'d will be cached according to normal Cloudflare cache behaviour
  • k

    kian

    03/09/2023, 1:20 AM
    If it's a Cloudflare customer, it'll be cached according to their rules
  • d

    Deleted User

    03/09/2023, 1:20 AM
    Aha!
  • k

    kian

    03/09/2023, 1:20 AM
    If they're not, it'll be cached under your zone and that behaviour can be controlled w/ some properties in the
    cf
    part of RequestInit
  • d

    dave

    03/09/2023, 2:18 AM
    Does doing a
    .tee()
    on a response cause extra memory to be used if one reader is slower than the other?
  • d

    dave

    03/09/2023, 2:18 AM
    I want to basically return the response, and cache it too
  • a

    Ariful

    03/09/2023, 2:19 AM
    Hi, is there any way I can use remote mysql database with prisma in the worker?
  • k

    kian

    03/09/2023, 2:20 AM
    The faster stream is back pressured to the speed of the slower
  • k

    kian

    03/09/2023, 2:21 AM
    If you only read one branch then the other branch is buffered into memory - but you'd be warned about that in the logs.
  • d

    dave

    03/09/2023, 2:22 AM
    hmm so I should probably do two fetch's then?
  • k

    kian

    03/09/2023, 2:23 AM
    I've never had issues personally - the only thing of note is that if you're using waitUntil then the stream must be consumed within 30 seconds.
  • k

    kian

    03/09/2023, 2:23 AM
    Now that's probably a confusing sentence, so I'll elaborate
  • k

    kian

    03/09/2023, 2:24 AM
    if I do
    const resp = await fetch(url);
    and then
    const [foo, bar] = resp.body.tee()
    and then
    ctx.waitUntil(env.R2.put(key, foo))
    and
    return new Response(bar)
    - the response being streamed to the client must be completed in under 30 seconds, since
    waitUntil
    currently has a bug where it starts the 30 second timer when the response headers are sent to the client rather than after the response body has finished streaming.
  • k

    kian

    03/09/2023, 2:24 AM
    If it isn't completed within 30 seconds, the
    waitUntil
    operation will be cancelled.
  • k

    kian

    03/09/2023, 2:25 AM
    Emphasis on currently has a bug - that's not intended behaviour
  • d

    dave

    03/09/2023, 2:27 AM
    what about if I do this instead?
    Copy code
    javascript
    const resp1 = await fetch(url)
    const resp2 = await fetch(url)
    ctx.waitUntil(env.R2.put(key, resp2.body))
    return resp1
  • k

    kian

    03/09/2023, 2:28 AM
    I wouldn't recommend it, there's latency from awaiting two requests, but it probably works
  • d

    dave

    03/09/2023, 2:29 AM
    better?
    Copy code
    javascript
    const resp1 = await fetch(url)
    const resp2 = fetch(url).then(async (response) => { return response.body })
    ctx.waitUntil(env.R2.put(key, resp2))
    return resp1
  • k

    kian

    03/09/2023, 2:30 AM
    I have no idea how the Worker will manage those promises (does waitUntil know to wait for resp2)
  • k

    kian

    03/09/2023, 2:30 AM
    but you could try it
  • d

    dave

    03/09/2023, 2:31 AM
    Copy code
    javascript
    const resp1 = await fetch(url)
    const my_promise = fetch(url).then(async (response) => { env.R2.put(key, response.body) })
    ctx.waitUntil(my_promise)
    return resp1
  • d

    dave

    03/09/2023, 2:31 AM
    better? 😄
  • k

    kian

    03/09/2023, 2:31 AM
    https://tenor.com/view/wait-what-confused-um-squint-gif-13025511
  • k

    kian

    03/09/2023, 2:32 AM
    are you streaming files that won't be downloaded by the user within 30 seconds
  • k

    kian

    03/09/2023, 2:32 AM
  • k

    kian

    03/09/2023, 2:33 AM
    there's a workaround to the issue that kenton posted which is probably less cursed than this
  • d

    dave

    03/09/2023, 2:33 AM
    I'm accepting temporary arbitrary files from untrusted random users
  • k

    kian

    03/09/2023, 2:33 AM
    https://stackoverflow.com/a/75248062/19639237
  • d

    dave

    03/09/2023, 2:33 AM
    oh wait put returns a promise too right?
1...233023312332...2509Latest