Is it safe to use `env.HYPERDRIVE.

Is it safe to use env.HYPERDRIVE.connectionString in the global context?
6 Replies
thomasgauvin
thomasgauvin3w ago
The env is provided via the fetch parameters, so not sure if that's what your looking for. See sample code https://developers.cloudflare.com/hyperdrive/get-started/#write-a-worker
Cloudflare Docs
Get started · Hyperdrive
Hyperdrive accelerates access to your existing databases from Cloudflare Workers, making even single-region databases feel globally distributed.
dave
daveOP3w ago
I'm thinking of caching the postgresql js client in the global scope.
AJR
AJR3w ago
That connectionString is not a secret, it is generated based on your binding and will only be usable by the account that owns the binding. I would say yes, it is safe to post on Reddit if you want to.
dave
daveOP3w ago
Will it change though?
AJR
AJR3w ago
Ah. That's a good question, sorry I missed the implication there. I'm not an expert on the runtime internals, so best I can say is "it might".
Hello, I’m Allie!
General recommendation is to not cache anything globally that relies on env I don’t think it can change without a full isolate reload right now, but I don’t think we provide any guarantees it will stay that way

Did you find this page helpful?