During development when I use my DOs… for the most part… things work. But if I restart my worker or the worker itself changes and rebuilds… my DOs seem to wipe their data.
Is this the case??
Is it only in production that DOs actually store data?
I ask because in my back office it’s showing that I am using some DO storage space. But I don’t think I have any DOs in production yet. Maybe one from a test Worker when I was learning how all of this works.
Can somebody confirm this for me. Thanks!
By “during development” do you mean wrangler dev? If you’re running wrangler dev on a script that implements a Durable Object, state.storage writes will update memory only, not persistent storage. That’s intended behavior.
It’s more complicated if you’re running wrangler dev on a script that binds to a Durable Object defined in a different script, but you should get a warning in that case - see Warn when wrangler dev is being used on a worker that binds to a durable object class implemented by a different script · Issue #319 · cloudflare/wrangler2 · GitHub
Thanks for confirming that for me. I just wanted to make sure.
Do you think there will ever be a “dev” or “preview” durable object so we can better test in our dev environments?
You’re saying you want to be able to make persistent storage changes from wrangler dev?
At least in the meantime, if you separate out the script that defines the durable object from the script that binds to and uses it, you can do that - see the link I posted above.
Or you can do non-dev writes through the durable object, and dev should start with a copy of that data.
Sorry for the late reply.
Thanks I will try some of this in a play Worker. I appreciate it!