Shared resources with multiple executions

So I'm just now finding out that resources might be shared acoss multiple instances. For instance, one library loading a cache and setting variables may end up being overwritten by a second execution. So if you cache language dictionaries and the users preferred language but another user with a different language runs code, it might switch to a totally different language. Just curious if this is true or not? 👀
9 Replies
Peps
Peps•4d ago
isolates do get re-used if you mean that any variables outside the request's scope will continue to persist, as long the isolate/instance of the worker is still alive
Walshy
Walshy•3d ago
^ not really sure why how you'd expect any global scope caching to work otherwise tbh. Workers has no idea different users, it just nows we can re-use an existing isolate and will do
Dubz
DubzOP•3d ago
Honestly more that I didn't know it was a thing lol. So I assume env and such inside functions is excluded?
Peps
Peps•3d ago
env is not part of the global scope, that's given for each request
Dubz
DubzOP•3d ago
Gotcha. Yeah. I'll have to tweak it a little then since the own stuff I added doesn't consider that. I believe everything else should be fine though. How long does a worker stay cached?
Peps
Peps•3d ago
a worker instance/isolate can stay alive for a undetermined amount of time. Kinda depends on your traffic patterns, whether Cloudflare is rolling out a runtime update, etc
Dubz
DubzOP•3d ago
So basically anywhere from the execution time to indefinitely? Lol
Walshy
Walshy•3d ago
pretty much obviously it's not that much. But, can be hours or a few days max.
Dubz
DubzOP•2d ago
Gotcha, makes sense. Shouldn't be too difficult for me to adapt to.

Did you find this page helpful?