1
votes

In Azure Functions i can easily create an input binding to a Cosmos DB Connection and specify a SqlQuery to get some data passed into my function on every call as described here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb#input---example-2

I'm wondering if this query is executed on every call of the function or if some sort of caching occurs behind the scenes (maybe even using ChangeFeed or some other mechanism to detect changes) ?

When the data coming from the query doesn't change very often, i guess querying the data myself and storing it in a static cache in my function would be more efficient.

1
your assumptions are rightThomas
yeah, checking requests to my cosmos db proves it as well. this should clearly be stated in the documentation imhoMarkus S.
Yes, querying the data yourself and storing it in a static cache in function would be more efficient.Rafat Sarosh

1 Answers

1
votes

The query will be executed every time.

Azure Functions have stateless nature. Even though some things can and should be reused between requests (e.g. connections to remote resources), for the most things you should assume that all loading will happen every time.

Depending on query results, caching each and every one of them could consume significant amount of memory. Remember that you pay for memory consumption.

Also, I am not sure if there is a way to cache the results of a custom Cosmos DB query and then have a reliable cache invalidation, even based on the change feed.

Overall, caching might be effective in your scenario, but it can't be effective in all scenarios. So, caching by default can't be a thing.