When a query such as the one below is fired and cached:
If I fire this query again (within stale-time) but the max date has changed by 10 minutes, will the cache be used (where it can, but also hit the db for anything in the extra 10 minutes), or will the fact that a query parameter has changed result in a new cached entity (meaning we've completely skipped the previous cache)?
let items = await client
.database("model-results")
.container("historicals")
.items.query({
query:
"SELECT * FROM c WHERE c.partitionKey = @partitionKey AND (c.dataDate BETWEEN @fromDate AND @toDate)",
parameters: [
{
name: "@partitionKey",
value: partitionKey,
},
{
name: "@fromDate",
value: min.toISOString(),
},
{
name: "@toDate",
value: max.toISOString(),
},
],
})
.fetchAll()
.catch((err) => {
throw err;
});
CodePudding user response:
If your query has different parameters, it will result in a cache miss. There is no "partial cache hit".
Query cache
The query cache can be used to cache queries. The query cache transforms a query into a key/value lookup where the key is the query text and the value is query results. The integrated cache doesn't have a query engine, it only stores the key/value lookup for each query.
If the cache does not have a result for that query (cache miss), the query is sent to the backend. After the query is run, the cache will store the results for that query
You can probably check if the cache was used by checking the RU charge of your query.
https://docs.microsoft.com/en-us/azure/cosmos-db/integrated-cache#query-cache