spring 集成memcached的详细介绍
2015-07-16 10:43
656 查看
前提条件:工程需要引入jar包java_memcached-release_2.0.1.jar
配置文件内容如下:
memcache.server=xxx.xxx.xxx.xxx:11111
memcache.weights=1
memcache.initConn=1
memcache.minConn=1
memcache.maxConn=50
memcache.maintSleep=3000
memcache.nagle=false
memcache.socketTO=3000
下面看一下com.danga.MemCached.SockIOPool的源代码,重点是SockIOPool构造函数:
下面看一下com.danga.MemCached.MemCachedClient的源代码,重点是MemCachedClient的构造函数:
转载自:Spring集成memcached的详细介绍
第一步:添加memcached的配置文件。
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="false" /> <property name="locations"> <list> <value>classpath:memcache.properties</value> </list> </property> </bean>
配置文件内容如下:
memcache.server=xxx.xxx.xxx.xxx:11111
memcache.weights=1
memcache.initConn=1
memcache.minConn=1
memcache.maxConn=50
memcache.maintSleep=3000
memcache.nagle=false
memcache.socketTO=3000
第二步:添加memcached的bean管理。
<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize" destroy-method="shutDown"> <constructor-arg><value>memCachedPool</value></constructor-arg> <property name="servers"><list><value>${memcache.server}</value></list></property> <property name="weights"><list><value>${memcache.weights}</value></list></property> <property name="initConn"><value>${memcache.initConn}</value></property> <property name="minConn"><value>${memcache.minConn}</value></property> <property name="maxConn"><value>${memcache.maxConn}</value></property> <property name="maintSleep"><value>${memcache.maintSleep}</value></property> <property name="nagle"><value>${memcache.nagle}</value></property> <property name="socketTO"><value>${memcache.socketTO}</value></property> </bean>
下面看一下com.danga.MemCached.SockIOPool的源代码,重点是SockIOPool构造函数:
public static synchronized SockIOPool getInstance(String poolName) { if (pools.containsKey(poolName)) return pools.get(poolName); SockIOPool pool = new SockIOPool(); pools.put(poolName, pool); return pool; }
<bean id="memCacheClient" class="com.danga.MemCached.MemCachedClient"> <constructor-arg><value>memCachedPool</value></constructor-arg> </bean>
下面看一下com.danga.MemCached.MemCachedClient的源代码,重点是MemCachedClient的构造函数:
public MemCachedClient(String poolName) { this.poolName = poolName; init(); }
第三步:测试memcached的功能。
public class MemcacheTest { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); MemCachedClient memCachedClient=(MemCachedClient)context.getBean("memCacheClient"); memCachedClient.set("hello", "swiftlet"); memCachedClient.get("hello"); } }
转载自:Spring集成memcached的详细介绍
相关文章推荐
- 实战Memcached缓存系统
- Redis和Memcached的区别详解
- PHP MemCached 高级缓存应用代码
- PHP模块 Memcached功能多于Memcache
- php的memcached客户端memcached
- php模块memcache和memcached区别分析
- 探讨:如何通过stats命令分析Memcached的内部状态
- 利用Memcached在php下实现session机制 替换PHP的原生session支持
- ubuntu+php环境下的Memcached 安装方法
- Nginx HttpMemcModule和直接访问memcached效率对比测试
- PHP内存缓存Memcached类实例
- Memcached常用命令及使用说明
- Memcached 入门介绍(安装与配置)
- PHP扩展模块memcached长连接使用方法分析
- Shell脚本实现的memcached进程监控
- linux下编译安装memcached服务
- php扩展memcached和memcache的安装配置方法
- PHP模块memcached使用指南
- 深入eAccelerator与memcached的区别详解
- Memcached常用命令以及使用说明详解