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

    dkfdkdodkms

    05/02/2023, 12:10 PM
    if i store a kv in response to a user request, will the kv value be immediately available to that user for subsequent requests? essentially, is there some kind of functions affinity, so i don't need to wait 60 seconds for the user responsible for setting a kv?
  • h

    HardAtWork

    05/02/2023, 2:25 PM
    In general, if a user request placed a value into KV, it will be stored/updated immediately, in that datacenter, and then it can take up to 60 seconds(or more if you set a cache TTL) to update in other datacenters. Though note that in rare cases, the local update can fail
  • d

    dkfdkdodkms

    05/02/2023, 2:27 PM
    but there is no guarantee a user will connect to the same datacenter on a subsequent call, correct?
  • h

    HardAtWork

    05/02/2023, 2:28 PM
    No, but that is pretty rare, unless a datacenter goes down(or your ISP messes with their BGP config)
  • h

    HardAtWork

    05/02/2023, 2:28 PM
    And there isn’t much of a way to prevent that
  • d

    dkfdkdodkms

    05/02/2023, 2:31 PM
    for the bgp config (no idea what this is), is this a one time issue type of thing. or would this causes problems with every connection for affected users?
  • d

    dkfdkdodkms

    05/02/2023, 2:32 PM
    essentially, i am looking to use KV for registration followed by immediate authentication, and wondering if it is reasonable to assume i could get away with this 99.8% of the time
  • h

    HardAtWork

    05/02/2023, 2:33 PM
    Basically, BGP is used to plan out routes on the internet(how to get from your IP address to the target IP address). If your ISP does it badly, you could end up being routed to a datacenter a country or three away, and you would have basically no recourse, other than contacting your ISP
  • h

    HardAtWork

    05/02/2023, 2:33 PM
    If you don’t have a lot of reads on the individual keys, it might be better to use a Durable Object
  • d

    dkfdkdodkms

    05/02/2023, 2:35 PM
    i would like to, but durable objects are so specialized, i am worried about being too locked in to cloudflare services
  • d

    dkfdkdodkms

    05/02/2023, 2:35 PM
    but i do like them!
  • h

    HardAtWork

    05/02/2023, 2:35 PM
    If you build it right, you can just treat it as it’s own kind of KV store
  • h

    HardAtWork

    05/02/2023, 2:36 PM
    There will be a little bit of rewriting should you decide to switch providers, but it shouldn’t be too bad
  • d

    dkfdkdodkms

    05/02/2023, 2:38 PM
    thank you. i will look into that
  • d

    dkfdkdodkms

    05/02/2023, 2:59 PM
    i think part of the problem is that i am trying to use pages and workers together (so i can use durable objects), calling workers from function scripts. i am thinking now to use just workers for the api part, but i don't want to lose the ability to make a call to the server without having to know the url. right now i can just call './login' from the client side. so, is there a way i can do the same with workers? can i maybe use a pages function to get me the url of a worker?
  • d

    dkfdkdodkms

    05/02/2023, 3:12 PM
    hm, it looks like "route" may be the answer. thank you
  • h

    HardAtWork

    05/02/2023, 3:32 PM
    You don’t actually need the Worker itself to be able to receive DO calls
  • h

    HardAtWork

    05/02/2023, 3:33 PM
    The Worker can just expose the DO, and then your Functions bind to that DO
  • d

    dkfdkdodkms

    05/02/2023, 3:36 PM
    yeah, but it is a little confusing, with the code in different places and two different ways of doing things (the pages way and workers way). it seems i am just using pages so i can make calls without having to have a hardcoded url in the client. is there a way of doing this with workers? so i can essentially make client calls doing this: './auth'? rather than 'somedomain:somport/auth'?
  • d

    dkfdkdodkms

    05/02/2023, 3:43 PM
    the only way that comes to mind is binding workers to a function, and having the function return the url of the worker, or proxying it. but then i am still using pages and workers
  • h

    HardAtWork

    05/02/2023, 3:45 PM
    Calling a DO in #910978223968518144 should be no more difficult than in Workers. For example, in Workers:
    Copy code
    ts
    export default <ExportedHandler<Env>> {
      async fetch(req, env) {
        // You can modify the request here, if you want
        return env.DO_BINDING.get(env.DO_BINDING.idFromName("someRandomName")).fetch(req);
      }
    }
    , and in #910978223968518144:
    Copy code
    ts
    export const onRequestGet: PagesFunction<Env> = (ctx) => {
      return ctx.env.DO_BINDING.get(ctx.env.DO_BINDING.idFromName("someRandomName")).fetch(ctx.request);
    }:
  • h

    HardAtWork

    05/02/2023, 3:46 PM
    This also reduces costs, since the Worker itself is never invoked
  • d

    dkfdkdodkms

    05/02/2023, 3:49 PM
    thank you, but the problem is my setup gets too complicated. i have a certain config for pages, and one for workers, code in different places... i don't know. my memory is not that great. i need to simplify things a bit
  • h

    HardAtWork

    05/02/2023, 3:50 PM
    You can simplify it by putting all of your Worker code in Functions, other than the DO, that has to be deployed separately?
  • d

    dkfdkdodkms

    05/02/2023, 3:52 PM
    but the do will likely need to use some things like r2 and kv, which will complicate the setup a bit. also, it seems the only thing pages can do is fetch, so a good portion of logic would be in DOs as well
  • h

    HardAtWork

    05/02/2023, 3:54 PM
    #910978223968518144 can natively bind to R2 & KV > Use bindings to integrate your Pages Functions with Cloudflare resources like KV, Durable Objects, R2, and D1. https://developers.cloudflare.com/pages/platform/functions/bindings/
  • d

    dkfdkdodkms

    05/02/2023, 3:55 PM
    thank you. but i don't see any info on doing this via localhost
  • s

    Skye

    05/02/2023, 3:56 PM
    The docs mention that for each binding on that page
  • d

    dkfdkdodkms

    05/02/2023, 3:57 PM
    ah, yes, you are correct. i think this is what i tried originally, had problems, and ended up binding using workers. i will try again. thank you
  • d

    dkfdkdodkms

    05/02/2023, 4:00 PM
    oops, actually, durable objects is missing. that was the issue
1...383384385...392Latest