memcache 入门

来源:互联网 发布:c语言max函数头文件 编辑:程序博客网 时间:2024/06/05 08:22
size=large]
Java中对memcache的实现有3种比较出名,memcached client for java、spymemcached、以及xmemcache。
较早之前的一些比较主要是集中在java memcached client和spymemcached之间
普遍的结论是:spymemcached校之java memcached client有更高的性能,但却没有java memcached client稳定。随着java memcached client新版本的发布,一些新的对比测试标明java memcached client在性能上并不比spymemcached逊色多少,再加上java memcached client被广泛使用,表现稳定,因此在一般情况下java memcached client是首选的memcache client.

还有一个由中国人编写的名为XMemcached的后起之秀
这个产品的性能表现是非常优秀的。但在使用的普遍性和项目未来的可维护上,在选型上需要慎重考虑。


综合考虑,java memcached client是一个稳妥的选择。

spring memcache 集成

applicationContext-mem.xml

Java代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  3. "http://www.springframework.org/dtd/spring-beans.dtd">
  4. <beans>
  5. <bean id="properties"
  6. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  7. <property name="locations">
  8. <list>
  9. <value>classpath:memcache.properties</value>
  10. </list>
  11. </property>
  12. </bean>
  13. <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
  14. factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
  15. <constructor-arg>
  16. <value>memCachedPool</value>
  17. </constructor-arg>
  18. <property name="servers">
  19. <list>
  20. <value>${memcache.server}</value>
  21. </list>
  22. </property>
  23. <property name="initConn">
  24. <value>${memcache.initConn}</value>
  25. </property>
  26. <property name="minConn">
  27. <value>${memcache.minConn}</value>
  28. </property>
  29. <property name="maxConn">
  30. <value>${memcache.maxConn}</value>
  31. </property>
  32. <property name="maintSleep">
  33. <value>${memcache.maintSleep}</value>
  34. </property>
  35. <property name="nagle">
  36. <value>${memcache.nagle}</value>
  37. </property>
  38. <property name="socketTO">
  39. <value>${memcache.socketTO}</value>
  40. </property>
  41. </bean>
  42. <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
  43. <constructor-arg>
  44. <value>memCachedPool</value>
  45. </constructor-arg>
  46. </bean>
  47. <!--添加bean去初始化我们自己的一个spring工具类 -->
  48. <bean id="springContextHolder" class="com.support.cps.utils.SpringContextHolder"/>
  49. </beans>

原创粉丝点击