https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • i

    ItsWendell

    08/07/2021, 5:16 PM
    Also I am trying to have an in-memory list of connected users to a Durable Object. Basically doing
    this.users = {}
  • i

    ItsWendell

    08/07/2021, 5:16 PM
    and as soon as a user connects I do
    this.users[message.id] = webSocket
  • i

    ItsWendell

    08/07/2021, 5:16 PM
    But when I have an query that tries to get those in memory users I get returned nothing, it stays empty
  • a

    albert

    08/07/2021, 5:28 PM
    Do the "automatically cached"
    await this.state.storage.get(key)
    -operations count as billable reads?
  • j

    john.spurlock

    08/07/2021, 5:31 PM
    https://discord.com/channels/595317990191398933/773219443911819284/869603323106426931
  • a

    albert

    08/07/2021, 5:33 PM
    That message was sent before this blog post was made - does it still apply?
  • a

    albert

    08/07/2021, 5:34 PM
    Nevermind, these changes were made a couple of weeks before that blog post, so the answer is probably yes.
  • j

    john.spurlock

    08/07/2021, 5:37 PM
    yea he had mentioned having the blog post written back when the change was deployed, but holding off on the blog post until after "impact week". Although pricing around DO is not completely nailed down yet, I'd be surprised if cached reads were not billed at the same rate. I guess we'll find out : )
  • a

    albert

    08/07/2021, 5:37 PM
    I'm just asking cause I need to decide whether to store the value as a variable or just read it each time
  • j

    john.spurlock

    08/07/2021, 5:39 PM
    imo variables every time - but unfortunately it's still possible to store too much (even like 12mb) so that a bunch of these instantiated into the same isolate will collectively blow the per-isolate memory limit. But that will depend on how you are accessing, how many you have at once, etc
  • v

    Vanessa🦩

    08/07/2021, 7:46 PM
    Even more convenient night be an “ephemeral/durable hybrid” object that automatically delegates storage ops to elsewhere - trading storage latency for client latency if the colo doesn’t support DOs directly.
  • v

    Vanessa🦩

    08/07/2021, 7:48 PM
    Wrangler only shows the log after a request has finished. For a websocket connection that can be a very long time.
  • v

    Vanessa🦩

    08/07/2021, 7:59 PM
    Am I interpreting this correctly that it is possible a worker and a DO may be loaded into the same isolate if they are the same script, sharing the same global scope? Or put differently, every isolate loads the whole script, and then it may receive a worker fetch as well as a DO instantiation+fetch?
  • w

    Wallacy

    08/07/2021, 8:03 PM
    We use KV with itty-durable because many of our data is bigger than DO value size and also the distributed side of the KV is also nice!
  • h

    HardAtWork

    08/07/2021, 8:08 PM
    So you wrap KV in itty-durable?
  • w

    Wallacy

    08/07/2021, 8:10 PM
    I just make my own midleware to handle the KV calls. Nothing fancy.
  • h

    HardAtWork

    08/07/2021, 8:14 PM
    Sorry, I was misinterpreting "using KV with itty-durable" as "using itty-durable as an interface for KV". My mistake!
  • w

    Wallacy

    08/07/2021, 9:46 PM
    I read that way…. Apear to be a reasonable trade off. But the behavior should be better documented.
  • w

    Wallacy

    08/08/2021, 3:14 AM
    That can also work, you just need to override the "persist" method.
  • k

    kenton

    08/08/2021, 4:45 PM
    That's correct. We try not to load two copies of the same script on the same machine, unless traffic levels actually require it.
  • a

    albert

    08/08/2021, 4:59 PM
    Is it possible to access the value passed to
    idFromName()
    from inside the Durable Object?
  • j

    john.spurlock

    08/08/2021, 5:04 PM
    Nope, just the hex id. You'll need to pass it down in your
    fetch
    call as a parameter if you want it inside the DO
  • a

    albert

    08/08/2021, 5:08 PM
    Alright, that's what I figured. Would be nice to have the option it in the future, but I don't see how it could be easily implemented :/
  • j

    john.spurlock

    08/08/2021, 5:10 PM
    Yea it would be nice if it was available off of the
    state
    passed to the instance, but I bet the name string is just an input to a hash function and never leaves the client side.
  • b

    brett

    08/08/2021, 8:38 PM
    The issue is you can do idFromName and then just use that ID in the future. We don’t store the original name anywhere. Best to make a small abstraction that passes the name along every time like you said.
  • h

    HardAtWork

    08/08/2021, 8:39 PM
    Can you hard-code an id, if you don't want to regenerate it on every rerun?
  • b

    brett

    08/08/2021, 8:40 PM
    I’m not sure what exactly what you mean. You could do idFromName and then store that ID somewhere, which is what I was referencing above. But you can’t just provide your own ID without going through the system
  • b

    brett

    08/08/2021, 8:41 PM
    If you make an ID from a name though you could use it forever
  • h

    HardAtWork

    08/08/2021, 8:42 PM
    So say for example I was using a DO as a global cache. I don't need to have more than one DO active at one time. Could I generate an id using a name, push it to the terminal, copy it down, and then hard-code it into my code?
  • b

    brett

    08/08/2021, 8:43 PM
    Yeah for sure. If you were going to do that though I’d use a unique ID
1...143144145...567Latest