缓存中介 wso2 esb api [英] Cache Mediator wso2 esb api

查看:29
本文介绍了缓存中介 wso2 esb api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 wso2 esb 中创建了一个 API 来调用 rest-service.我使用了缓存中介,它适用于普通的 GET 方法.

I have created an API in wso2 esb to call the rest-service. I have used cache mediator, it's working fine for a normal GET method.

我想要的是,我使用了 GET 方法来获取员工详细信息,我将通过 url 传递员工 ID.

What i want is, I have used a GET Method to get the employee details, I will be passing the employee_id with the url.

这个 API 调用是第一次针对给定的 employee_id 调用服务,然后对于相同的 employee_id 的下一次调用,它应该从缓存本身获得响应,直到给定的超时期限.如果我更改了employee_id,那么它应该会命中服务,但它会从缓存中获取响应.也适用于不同的员工 ID.

This API call is hitting the service for the first time for a given employee_id, then for next call for the same employee_id it should get the response from the cache itself up-to the given Timeout period. if i change the employee_id then it should hit the service but it is getting the response from the cache. for different employee_id also.

我的 API 是,

<api xmlns="http://ws.apache.org/ns/synapse" name="cacheApi" context="/cacheApi">
<resource methods="GET" uri-template="/{id}/">
  <inSequence>
     <log/>
     <cache id="" scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator" timeout="60">
        <implementation type="memory" maxSize="10"/>
     </cache>
     <send>
        <endpoint>
           <http method="GET" uri-template="http://localhost:8080/rest-services/services/employee/{uri.var.id}"/>
        </endpoint>
     </send>
  </inSequence>
  <outSequence>
     <cache scope="per-host" collector="true"/>
     <send/>
  </outSequence>
</resource>
</api>

我的 API 调用如下,

My API call will be as,

http://localhost:8280/cacheApi/1
http://localhost:8280/cacheApi/2
http://localhost:8280/cacheApi/3
....

谁能帮我解决这个问题??

Can anyone help me to solve this??

提前致谢

推荐答案

您可以尝试一个新的哈希生成器实现,它也使用 API URI 来生成哈希值.

There is a new implementation of the hash generator that you can try, which uses the API URI as well for generating the hash value.

为了应用它,将哈希生成器设置为 org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator.

In order to apply that, set the hash generator to org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator.

现在你的缓存中介应该是这样的,

Now your cache mediator should like this,

<cache id="" scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator" timeout="60">
        <implementation type="memory" maxSize="10"/>
</cache>

(PS:我只针对 WSO2 ESB 4.9.0 版本进行了测试.)

(PS: I only tested this for the WSO2 ESB 4.9.0 release.)

这篇关于缓存中介 wso2 esb api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆