Azure Cosmos DB 集成缓存重用

Azure Cosmos DB Integrated Cache re-use

当触发并缓存如下查询时:

如果我再次触发此查询(在过时时间内)但最大日期已更改 10 分钟,是否会使用缓存(在可能的情况下,但也会在额外的 10 分钟内访问数据库以获取任何内容) ,或者查询参数已更改的事实是否会导致新的缓存实体(意味着我们已经完全跳过了以前的缓存)?

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;
    });

如果您的查询有不同的参数,将导致缓存未命中。没有“部分缓存命中”。

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

您可能可以通过检查查询的 RU 费用来检查是否使用了缓存。

https://docs.microsoft.com/en-us/azure/cosmos-db/integrated-cache#query-cache