是的,同意你的看法。理想情况下,应根据状态代码选择可缓存的响应。我刚刚创建了一个feature improvement request。
但是,运行时已经支持这一点,只有 UI 缺少它。
因此,您可以通过更改配置文件来使其工作。
为此,打开repository/resources/api_templates/velocity_template.xml 并搜索<cache scope="per-host" collector="false"。 (注collector=false)
然后,像这样在<implementation> 标记上方添加<protocol> 标记。
<cache scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator" timeout="$!responseCacheTimeOut">
<protocol type="HTTP">
<methods>*</methods>
<headersToExcludeInHash/>
<responseCodes>2[0-9][0-0]</responseCodes>
<enableCacheControl>false</enableCacheControl>
<includeAgeHeader>false</includeAgeHeader>
<hashGenerator>org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator</hashGenerator>
</protocol>
<implementation type="memory" maxSize="500"/>
</cache>
注意responseCodes 中 2xx 响应的正则表达式。我希望这能回答您的第一个问题。
关于密钥缓存,是的,网关和密钥管理器都有缓存。但默认情况下,仅启用网关缓存。
<CacheConfigurations>
<!-- Enable/Disable token caching at the Gateway-->
<EnableGatewayTokenCache>true</EnableGatewayTokenCache>
<!-- Enable/Disable API resource caching at the Gateway-->
<EnableGatewayResourceCache>true</EnableGatewayResourceCache>
<!-- Enable/Disable API key validation information caching at key-management server -->
<EnableKeyManagerTokenCache>false</EnableKeyManagerTokenCache>
在某些情况下,有些人希望禁用网关缓存并启用密钥管理器缓存,例如当网关位于 DMZ 时。