美好的一天,我现在对 infinispan javax.cache.annotation.CacheResult
的JBoss Enterprise Application Platform 6.1 和 6.3中的实现有点困惑。
我一直在谷歌搜索并浏览stackoverflow,但对于一直让我忙碌的问题,我还没有真正找到明确的答案。所以我走了。注释是否@CacheResult
需要其注释的方法中的参数。它使用参数实际为商店创建密钥。然而,它并没有真正记录如果你没有它会发生什么。对于想要返回存储在数据库中的国家/地区列表并且该列表不会经常更改的 Web 应用程序,可能会发生这种情况。
代码示例:
/**
* Fetches a list of Country's from the Database system trough the SOAP adapter.
*
* @return a lit of country's from the Database system.
*/
@CacheResult(cacheName = "referenceService/CountryListCache")
// The attributes sorted is used by the caching mechanism, as combined key for the (to be) cached CountryListCache object.
public List<Country> getCountryList() throws ReferenceServiceException_Exception {
LOG.debug("Cache is not used doing a full call to the service.");
ReferenceTableIdSO getter = //Create a getter that does the external query;
List<AlfaCodeDBObjectSO> transform = //calls the external system to get the data.
//Transform the external data to somtine we want to return.
List<Country> result = new ArrayList<Country>();
for (AlfaCodeDBObjectSO trans : transform) {
Country country = new Country(trans.getCode(), trans.getExplanation());
result.add(country);
}
return result;
}
EAP6.1.1的配置
<subsystem xmlns="urn:jboss:domain:infinispan:1.4">
<cache-container name="rest-cache" default-cache="default" start="EAGER">
<local-cache name="default">
<transaction mode="NONE"/>
<eviction strategy="LRU" max-entries="1000"/>
<expiration max-idle="3600000"/>
</local-cache>
<local-cache name="referenceService/CountryListCache">
<locking isolation="REPEATABLE_READ" acquire-timeout="15000"/>
<transaction mode="NONE" locking="PESSIMISTIC"/>
<eviction strategy="LRU" max-entries="1024"/>
<expiration lifespan="86400000"/>
</local-cache>
</cache-container>
</subsystem>
正如您在我的示例中看到的,我想减少代码调用。我将配置设置为每天刷新一次,以确保安全。但我实际上不确定该列表是否已缓存等。因为关于该方法是否没有参数的文档记录太差。