i want to have a big concurrencies with the cloud function, so I'm using the cloud function v2. But, in one of the steps, I want only 1 process can do it, while other processes need to wait for it.
Let's say that I have below logic for my function
if (notGenerated()) {
generateSomething()
}
step2()
step3()
...
If its 'not generated yet', and then there are 2 or more request coming at the same time, how can I block it so that only 1 process/request can do the generation?
In the conventional way, I would use redis as memory cache, to make sure that only 1 process can go through. The other processes could wait, or do any retries.
But if I need to implement the same style to my cloud function, I need to use the memorystore for redis and serverless vps connector, which is not cheap. Especially that in the memorystore, I would be charged for 24 hours, while I might only use it for 3-4 hours only.
How do you check / use the memory cache in cloud function v2? Could I use something like node-cache in cloud function v2? Does the concurrency in cloud function v2 share the same memory? If the cloud functions scale my functions, does it still using the same memory?
generateSomething()only once, even if my functions are called multiple times in the same time?generateSomething()method value like count and it should be 0 then execute that function. So with this you can break out from concurrency as your function further execution will be judged by that value.generateSomething()at the same time.