Microsoft Azure API管理-缓存策略不支持';行不通

Microsoft Azure API管理-缓存策略不支持';行不通,azure,azure-api-management,cache-control,policies,api-management,Azure,Azure Api Management,Cache Control,Policies,Api Management,我已尝试在Azure API管理中设置缓存策略,如下所示: <policies> <inbound> <base /> <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" must-revalidate="true" downstream-caching-type

我已尝试在Azure API管理中设置缓存策略,如下所示:

<policies>
    <inbound>
        <base />
        <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" must-revalidate="true" downstream-caching-type="none" caching-type="internal">
            <vary-by-query-parameter>KontoNr</vary-by-query-parameter>
        </cache-lookup>
        <set-backend-service id="apim-generated-policy" backend-id="LogicApp_GeldEinzahlen_APIM_f597e3433e7847cb9d689c3f95bf1d6d" />
        <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
            <openid-config url="https://login.microsoftonline.com/1b7c4ba5-7701-49e7-94d8-5ddbc87f8b6e/v2.0/.well-known/openid-configuration" />
            <required-claims>
                <claim name="aud">
                    <value>7068cdb6-0e5c-49c5-aaa8-ec8fc941de22</value>
                </claim>
            </required-claims>
        </validate-jwt>
        <set-variable name="isKontoNr" value="@(context.Request.MatchedParameters["kontoNr"].ToString().Length != 10)" />
        <choose>
            <when condition="@(context.Variables.GetValueOrDefault<bool>("isKontoNr"))">
                <return-response>
                    <set-status code="400" reason="Bad Request" />
                    <set-header name="WWW-Request" exists-action="override">
                        <value>Generell error="kontoNr invalid"</value>
                    </set-header>
                </return-response>
            </when>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
        <cache-store duration="1000" />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
无论我在头中发送什么,缓存控制总是“无缓存”


我怎样才能修好它?是否需要其他配置或是否启用了某些配置?

如注释中所述,消息
cache control:no cache
实际上不应指示是否正在使用缓存。APIM中的
策略是正确的

首次请求api(用于在APIM页面中进行测试)时,请单击“跟踪”-->“入站””。您可以找到消息“缓存查找导致未命中”,因为您第一次请求时没有缓存。

然后单击“出站”,您可以发现
响应将在流媒体传输期间被缓冲,并在完全接收后存储在缓存中。

然后,由于您指定缓存将存储1000秒,因此如果您在1000秒后再次请求,您可以找到消息
缓存查找导致命中入站”下编码>。


请在您这边进行测试,如果结果与我上面提到的相同,则策略
在您的APIM中运行良好。

无缓存pragma实际上不应指示是否正在使用缓存。转到APIM中的测试页面,运行查询并查看跟踪。在那里,您将看到是否使用了缓存查找Hi Pascal,如果我在下面提供的答案对您的问题有帮助,请您(单击我答案旁边的复选标记,将其从灰色切换为填充)将其设置为“已接受”,提前感谢。谢谢。我发现,对于带有授权标头的请求,默认情况下不会启用缓存。允许缓存私有响应解决了这个问题。
HTTP/1.1 200 OK

cache-control: no-cache
content-encoding: gzip
content-type: text/plain; charset=utf-8
date: Tue, 12 Jan 2021 15:54:26 GMT
expires: -1
pragma: no-cache
strict-transport-security: max-age=31536000; includeSubDomains