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;
        }
    
    }
  • 相关阅读:
    修改注册表启动项
    修改IP和DNS的dos命令
    屏蔽windows快捷键的方法
    本地IP,掩码,网关,DNS设置
    DevExpress的提示框
    ASP.NET如何批量保存动态生成的文本框?
    [转]SQL Server 安全性概論與無法刪除資料庫使用者的解決辦法
    如何用C#对Gridview的项目进行汇总统计?
    如何用javasript对Gridview的项目进行汇总统计?
    [转]C#如何获取客户端IP地址
  • 原文地址:https://www.cnblogs.com/xiaoliangup/p/9236202.html
Copyright © 2011-2022 走看看