如何使用 HTTP 响应状态代码配置 API 响应缓存?
How to configure API Response cache with HTTP Response status code?
我用 API 响应缓存测试了 APIM 性能。
结果和我的预期有点不同。
如下所示。
第一个 API 请求通过 API 网关从 API 服务获得 404 响应状态代码。
所以我预计第二个响应是来自 API 响应缓存的 404 响应状态代码。
但是它返回了 200 个响应状态代码(与第一个不同),响应主体相同。
我从 WSO2 文档中阅读了如下注释。
Cache mediator does not cache the response status code of the HTTP response in the cache table. Instead, it returns the "200 OK" status code on a cache hit, which is the default request success status response. If you want to return a different status code when the request gets a cache hit, you can update the response status code in the onCacheHit sequence.
我明白这张便条的意思,但我不知道该怎么做。
这不是我处理缓存中介的领域,尤其是中介语法。
我希望 API 响应缓存与 HTTP 响应状态代码一起使用。
有人可以指导我吗?
我找到了自己的方法来解决这个问题。
这可能是错误的,但它按我的预期工作。
(API 当 HTTP 响应代码为 200 和 GET 方法时,响应缓存有效。)
我编辑了 velopcity_templete.xml 文件,如下所示。
<inSequence>
...
## check and set response caching
#if($responseCacheEnabled)
#if($resource.getMethodsAsString() == 'GET')
<cache scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.REQUESTHASHGenerator" timeout="$!responseCacheTimeOut">
<implementation type="memory" maxSize="500"/>
</cache>
#end
...
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
## check and set response caching
#if($responseCacheEnabled)
#if($resource.getMethodsAsString() == 'GET')
<filter regex="200" source="$axis2:HTTP_SC">
<then>
<cache scope="per-host" collector="true"/>
</then>
</filter>
#end
#end
<send/>
</outSequence>
如果谁有更好更标准的方法,对我很有帮助。
我用 API 响应缓存测试了 APIM 性能。 结果和我的预期有点不同。 如下所示。
第一个 API 请求通过 API 网关从 API 服务获得 404 响应状态代码。 所以我预计第二个响应是来自 API 响应缓存的 404 响应状态代码。 但是它返回了 200 个响应状态代码(与第一个不同),响应主体相同。
我从 WSO2 文档中阅读了如下注释。
Cache mediator does not cache the response status code of the HTTP response in the cache table. Instead, it returns the "200 OK" status code on a cache hit, which is the default request success status response. If you want to return a different status code when the request gets a cache hit, you can update the response status code in the onCacheHit sequence.
我明白这张便条的意思,但我不知道该怎么做。 这不是我处理缓存中介的领域,尤其是中介语法。
我希望 API 响应缓存与 HTTP 响应状态代码一起使用。 有人可以指导我吗?
我找到了自己的方法来解决这个问题。
这可能是错误的,但它按我的预期工作。
(API 当 HTTP 响应代码为 200 和 GET 方法时,响应缓存有效。)
我编辑了 velopcity_templete.xml 文件,如下所示。
<inSequence>
...
## check and set response caching
#if($responseCacheEnabled)
#if($resource.getMethodsAsString() == 'GET')
<cache scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.REQUESTHASHGenerator" timeout="$!responseCacheTimeOut">
<implementation type="memory" maxSize="500"/>
</cache>
#end
...
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
## check and set response caching
#if($responseCacheEnabled)
#if($resource.getMethodsAsString() == 'GET')
<filter regex="200" source="$axis2:HTTP_SC">
<then>
<cache scope="per-host" collector="true"/>
</then>
</filter>
#end
#end
<send/>
</outSequence>
如果谁有更好更标准的方法,对我很有帮助。