Caching in-memory

Is there any way to cache data "in memory" rather than over the network as JSON etc.? The use case is we have a very large blob of JSON that we need to manipulate in a worker which is called at a very high rate. The JSON is cached via the existing "fetch" caching mechanism so that the delivery of the raw file itself is fast, but the problem is that every invocation of the worker needs to re-parse that JSON in order to use it. Is there any way to cache the actual parsed JSON object in-memory somewhere so that multiple invocations can use the already-parsed version of it without having to redo that parsing work?
4 Replies
Cyb3r-Jak3
Cyb3r-Jak310mo ago
You can use the cache api to store the filtered JSON or something like KV if you need it to stick around longer
Adam
AdamOP10mo ago
but dont both of those require serialization to store the data?
Cyb3r-Jak3
Cyb3r-Jak310mo ago
You can put either array buffers or json into KV but I believe the cache api can only use strings
Devon
Devon10mo ago
I don't think you can get around the deserialization issue with a stateless solution like Workers. At best maybe you could find a more efficient serialization/deserialization spec that you could still stash in KV, but... If it's something being called at a high rate generally, perhaps consider a stateful compute option (EC2/ECS/VM/real server)?
Want results from more Discord servers?
Add your server