sprimg+memcache

1.spring配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<context:component-scan base-package="com.spring.memcached"></context:component-scan>

<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance"
init-method="initialize">
<constructor-arg>
<value>neeaMemcachedPool</value>
</constructor-arg>
<property name="servers">
<list>
<value>127.0.0.1:11211</value>
</list>
</property>
<property name="initConn">
<value>20</value>
</property>
<property name="minConn">
<value>10</value>
</property>
<property name="maxConn">
<value>50</value>
</property>
<property name="socketTO">
<value>3000</value>
</property>
</bean>

<bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">
<constructor-arg>
<value>neeaMemcachedPool</value>
</constructor-arg>
</bean>
</beans>

2测试

public class SpringMemcached {
@Autowired
private MemCachedClient mcc;

public static void main(String[] args) {
// TODO Auto-generated method stub

ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

SpringMemcached sct = (SpringMemcached) ctx.getBean("springMemcached");

sct.mcc.set("spring", "memcached");

Object obj = sct.mcc.get("spring");

System.out.println("obj:"+obj);
}

}

相关文章

前言设计一个缓存系统,不得不要考虑的问题就是:缓存穿透、...
在192.168.80.100要联网关闭防火墙及SElinuxsystemctlstopfi...
Redis与Memcache对比:1.Memcache是一个分布式的内存对象缓存...
安装Mencache:关闭防火墙及SElinuxsystemctl  stop  fi...
#安装php的yaf模块,参考https://www.cnblogs.com/shifu204/...
win10下安装配置apache、php、mysql、redis、memcache资源官...