【问题标题】:WSO2: Caching Keys and ResponseWSO2:缓存键和响应
【发布时间】:2019-09-22 03:19:17
【问题描述】:

我是中间件技术的初学者。我从 WSO2 开始。现在我了解到 WSO2 在不同的地方都有缓存功能。其中两个是在 Key Manager 缓存 Keys 和 Response Caching。

我的问题很简单(天真),如果我们缓存了错误的响应,我们会再次得到响应。 例如: 我点击了这个虚拟 API 请求http://dummy.restapiexample.com/api/v1/employees,它应该给出一个员工列表,但它给了我 null 或其他东西。现在,此响应缓存在响应缓存中,这意味着我将继续获取 null。这是错误的。缓存是有道理的,但它会缓存所有响应,无论是对是错。那么它是怎么处理的,是什么概念呢?

同样适用于密钥管理器。在 API 网关级别和密钥管理器级别缓存密钥有什么意义?如果它是错误的密钥或过期的密钥,我们无论如何都必须重新生成它。

请回答。我的问题听起来很幼稚,但如果您能解释一下,我们将不胜感激。

【问题讨论】:

  • 您询问的是哪种产品。 API 管理器,或者企业集成商?

标签: caching wso2


【解决方案1】:

是的,同意你的看法。理想情况下,应根据状态代码选择可缓存的响应。我刚刚创建了一个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 时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多