This caching is per instance... the main issue with caching in memory, especially in something like a cloud function is functions aren't really long-lived. It's different if you're running few instances of a persistent service, quite another if you're in a FaaS.
Depending on the round-trip-time to the query service, it may be better to not cache. If it's expensive, then it's likely best to cache in an indexed key/value store such as redis or other local/near DB.
I totally agree but in some case a simple and quick solution is enough. I found this strategy in GCP documentation https://cloud.google.com/functions/docs/bestpractices/tips. I also warn in the article that the function execution environment isn't always preserved.