Memcached + Spring

来源:互联网 发布:java中嵌入javascript 编辑:程序博客网 时间:2024/06/06 07:32

 

一、application.xml配置如下:

<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="nagle"><value>false</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>


二、简单使用

 

 

 MemCachedClient cachedClient; ApplicationContext context = new ClassPathXmlApplicationContext("cfg/application.xml");cachedClient = (MemCachedClient)context.getBean("memcachedClient");UserBean user = new UserBean("lou111", "jason");cachedClient.set("user", user);UserBean cachedBean = (UserBean)cachedClient.get("user");/*System.out.println(cachedBean.toString());IUserMgmt userMgmt = (IUserMgmt) context.getBean("userMgmt");cachedBean = userMgmt.getUserByName("xiaoming");*/System.out.println(cachedBean.toString());


三、使用aop。在拦截器中使用,作为数据库缓冲、  在过滤器中使用,作为分布式部署的共享session

 

0 0
原创粉丝点击