simple-spring-memcached统一缓存的使用实例3

 

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);

    }

}

后续阅读下片博文,或到这里阅读http://wenku.it168.com/d_000750100.shtml

posted @ 2013-01-28 09:49  最轻  阅读(329)  评论(0编辑  收藏  举报