zoukankan      html  css  js  c++  java
  • Memcached和Spring集成开发

    xml配置文件

    <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
            factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
            <constructor-arg>
                <value>neeaMemcachedPool</value>
            </constructor-arg>
            <property name="servers">
                <list>
                    <value>192.168.174.104:2222</value>
                </list>
            </property>
            <property name="initConn">
                <value>5</value>
            </property>
            <property name="minConn">
                <value>5</value>
            </property>
            <property name="maxConn">
                <value>250</value>
            </property>
            <property name="maintSleep">
                <value>30</value>
            </property>
            <property name="nagle">
                <value>false</value>
            </property>
            <property name="maxIdle">
                <value>6000</value>
            </property>
            <property name="socketTO">
                <value>3000</value>
            </property>
        </bean>
        <!--memcached client -->
        <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
            <constructor-arg>
                <value>neeaMemcachedPool</value>
            </constructor-arg>
        </bean>

    JAVA调用

    @Primary
    @Repository
    public class GoodsMemDao implements GoodsDAO{
        
        private final String MEM_PRE="goods_";
        
        @Autowired
        private GoodsMapperDAO goodsDao;
        
        @Autowired
        private MemCachedClient memClient;
        
        
        public void create(GoodsModel m) {
            goodsDao.create(m);
        }
    
        public void update(GoodsModel m) {
            goodsDao.update(m);
            
            Object obj=memClient.get(MEM_PRE+m.getUuid());
            if(obj!=null){
                memClient.set(MEM_PRE+m.getUuid(), m);
            }
            
        }
    
        public void delete(Integer uuid) {
            goodsDao.delete(uuid);
            Object obj=memClient.get(MEM_PRE+uuid);
            if(obj!=null){
                memClient.delete(MEM_PRE+uuid);
            }
        }
    
        public GoodsModel getByUuid(Integer uuid) {
            
            Object obj=memClient.get(MEM_PRE+uuid);
            if(obj !=null){
                return (GoodsModel) memClient.get(MEM_PRE+uuid);
            }
        
            GoodsModel goods=goodsDao.getByUuid(uuid);
            memClient.set(MEM_PRE+uuid, goods);
            
            return goods;
        }
    
    }
  • 相关阅读:
    USACO 2016 February Contest, Gold解题报告
    USACO 2016 January Contest, Gold解题报告
    NOIP2013 Day2
    [DP题]放苹果
    [DP题]登山
    洛谷八连测R6
    [20171025模拟赛]
    [DP题]吃糖果
    [DP题]采药
    spring-security-oauth2 授权服务集成钉钉扫码登录
  • 原文地址:https://www.cnblogs.com/xiaoliangup/p/9236202.html
Copyright © 2011-2022 走看看