SSM框架整合 spring3.2.9 + spring mvc3.2.9 + mybatis3.2.8 + Druid数据源 + log4j2

接着上一篇SSM框架整合 spring3.2.9 + spring mvc3.2.9 + mybatis3.2.8 + Druid数据源 + log4j2

这次在此基础上引入了memcached缓存框架,

一、环境:

1、win7系统

2、memcached windows 64位服务端

3、java语言的memcach客户端实现:memcached client for java (java对memcache的实现有三种:memcached client for java,xmemcache,xmemcache)


二、需要下载的软件和jar :http://pan.baidu.com/s/1mgmV8bY  

memcached-win64-1.4.4-14.zip: win 64位的memcached安装包
memcached-1.4.24.tar.gz : linux版安装包
java_memcached-release_2.6.6.zip:java客户端所需jar 

三、spring配置

       <!-- 多个配置文件加载 -->
        <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
	    <property name="locations">  
	        <list>  
	            <value>classpath*:jdbc.properties</value>
	        	<value>classpath*:memcache.properties</value> 
	        </list>  
	    </property>  
	</bean>
       <!-- Memcached配置 -->  
    <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"  
        factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
        <property name="servers">
            <list>
                <value>${memcacheServer}</value>
            </list>
        </property>
        <property name="initConn">
            <value>${memcacheInitConn}</value>
        </property>
        <property name="minConn">
            <value>${memcacheMinConn}</value>
        </property>
        <property name="maxConn">
            <value>${memcacheMaxConn}</value>
        </property>
        <property name="maintSleep">
            <value>${memcacheMaintSleep}</value>
        </property>
        <property name="nagle">
            <value>${memcacheNagle}</value>
        </property>
        <property name="socketTO">
            <value>${memcacheSocketTO}</value>
        </property>
    </bean>
    <!-- memcached客户端操作对象 -->
    <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient"></bean>

四、memcache.properties

#memcached服务端ip和端口号
memcacheServer=127.0.0.1:11211
#连接池初始连接数
memcacheInitConn=5
#连接池最小连接数  
memcacheMinConn=5
#连接池最大连接数
memcacheMaxConn=50
#自查线程周期进行工作,其每次休眠时间
memcacheMaintSleep=30000
#Socket的参数,如果是true在写数据时不缓冲,立即发送出去
memcacheNagle=false
#Socket阻塞读取数据的超时时间
memcacheSocketTO=3000

上面就已经初步完成了memcached的集成配置了,使用的时候只需要注入MemCachedClient对象即可

@Resource
private MemCachedClient memcachedClient;

然后就可以用memcachedClient 执行 set add get clear等操作。

这只是一种简单的实现,需要手动将数据放入缓存库。



猜你喜欢

转载自blog.csdn.net/iverson3sod/article/details/46390369
今日推荐