简体   繁体   English

Azure Cosmos DB 集成缓存重用

[英]Azure Cosmos DB Integrated Cache re-use

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)?如果我再次触发此查询(在陈旧时间内)但最大日期已更改 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;
    });

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.您可以通过检查查询的 RU 费用来检查是否使用了缓存。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM