Java代码中使用说明
a. 注解方式使用
直接使用注解来处理缓存及失效非常简单,下面是相应的例子:
读取缓存:EventGoodsServiceClientImpl.java
@Override
@ReadThroughSingleCache(namespace = "goodscenter:EventGoodsDo", expiration = 60)
@CacheName("appCache")
public EventGoodsDo queryEventGoodsDo(@ParameterValueKeyProvider(order = 0) long goodsId, @ParameterValueKeyProvider(order = 1) long eventId) {
return getRemoteServiceBean().queryEventGoodsDo(goodsId, eventId);
}
更新缓存:
EventGoodsDaoImpl.java
@BridgeMethodMappings(value = {@BridgeMethodMapping(erasedParamTypes ={Object.class},targetParamTypes = {com.hqb360.promotion.dao.entity.EventGoods.class},methodName = "update")})
public class EventGoodsDaoImpl<EventGoods> extends BaseDaoImpl<EventGoods> implements EventGoodsDao<EventGoods> {
@Override
public DaoStatementName getDaoStatementName() {
return new DefaultDaoStatementName() {
public String getDomainName() {
return "EventGoods";
}
};
}
@Override
@InvalidateSingleCache(namespace = "goodscenter:EventGoodsDo")
@CacheName("appCache")
public void update(@ParameterValueKeyProvider EventGoods obj) throws DataAccessException {
super.update(obj);
}
}
后续阅读下片博文,或到这里阅读