spring 管理 memcached

spring配置

Xml代码

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beans
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
  7. <!--memcached客户端***start-->
  8. <beanid="memcachedPool"class="com.danga.MemCached.SockIOPool"factory-method="getInstance"init-method="initialize"destroy-method="shutDown">
  9. <constructor-arg>
  10. <value>neeaMemcachedPool</value>
  11. </constructor-arg>
  12. <propertyname="servers">
  13. <list>
  14. <value>192.168.54.207:12345</value>
  15. <!--多服务器
  16. <value>
  17. 192.168.54.207:12346
  18. </value>
  19. -->
  20. </list>
  21. </property>
  22. <!--多服务器负载均衡-->
  23. <!--<propertyname="weights">
  24. <value>5,5</value>
  25. </property>-->
  26. <propertyname="initConn">
  27. <value>20</value>
  28. </property>
  29. <propertyname="minConn">
  30. <value>10</value>
  31. </property>
  32. <propertyname="maxConn">
  33. <value>500</value>
  34. </property>
  35. <propertyname="maintSleep">
  36. <value>30</value>
  37. </property>
  38. <propertyname="nagle">
  39. <value>false</value>
  40. </property>
  41. <propertyname="maxIdle">
  42. <value>6000</value>
  43. </property>
  44. <propertyname="socketTO">
  45. <value>3000</value>
  46. </property>
  47. </bean>
  48. <!--memcachedclient-->
  49. <beanid="memcachedClient"class="com.danga.MemCached.MemCachedClient">
  50. <constructor-arg>
  51. <value>neeaMemcachedPool</value>
  52. </constructor-arg>
  53. <propertyname="compressEnable">
  54. <value>true</value>
  55. </property>
  56. <propertyname="compressThreshold">
  57. <value>4096</value>
  58. </property>
  59. </bean>
  60. <!--memcached客户端***end-->
  61. <!--如果换客户端或者换缓存了,在web.mxl里切换加载对应的配置文件即可-->
  62. <beanid="cache"class="com.xxx.CacheClientImpl">
  63. <propertyname="cacheProvider"ref="memcachedClient"/>
  64. </bean>
  65. </beans>

java代码

import java.util.Date;

import com.danga.MemCached.MemCachedClient;
import com.kanmenzhu.cache.ICacheClient;

/**缓存的一个实现类(memcached client)
* @author lydawen 2009-11-27
*
*
*/
public class CacheClientImpl{

private MemCachedClient cacheProvider;

@Override
public boolean add(String key, Object value) {
return this.cacheProvider.add(key, value);
}

@Override
public boolean add(String key, Object value, long expiry) {
return this.cacheProvider.add(key, value, new Date(expiry));
}

@Override
public boolean add(String key, Object value, long expiry, Integer hashCode) {
return this.cacheProvider.add(key, value, new Date(expiry), hashCode);
}

@Override
public boolean add(String key, Object value, Integer hashCode) {
return this.cacheProvider.add(key, value, hashCode);
}

@Override
public boolean delete(String key) {
return this.cacheProvider.delete(key);
}

@Override
public boolean delete(String key, long expiry) {
return this.cacheProvider.delete(key, new Date(expiry));
}

@Override
public boolean delete(String key, Integer hashCode, long expiry) {
return this.cacheProvider.delete(key,hashCode,new Date(expiry));
}

@Override
public Object get(String key) {
return this.cacheProvider.get(key);
}

@Override
public Object get(String key, Integer hashCode) {
return this.cacheProvider.get(key, hashCode);
}

@Override
public Object get(String key, Integer hashCode, boolean asString) {
return this.cacheProvider.get(key, hashCode, asString);
}

@Override
public boolean keyExists(String key) {
return this.cacheProvider.keyExists(key);
}

@Override
public boolean replace(String key, Object value) {
return this.cacheProvider.replace(key, value);
}

@Override
public boolean replace(String key, Object value, long expiry) {
return this.cacheProvider.replace(key, value, new Date(expiry));
}

@Override
public boolean replace(String key, Object value, long expiry,
Integer hashCode) {
return this.cacheProvider.replace(key, value, new Date(expiry), hashCode);
}

@Override
public boolean replace(String key, Object value, Integer hashCode) {
return this.cacheProvider.replace(key, value, hashCode);
}

@Override
public boolean set(String key, Object value) {
return this.cacheProvider.set(key, value);
}

@Override
public boolean set(String key, Object value, long expiry) {
return this.cacheProvider.set(key, value, new Date(expiry));
}

@Override
public boolean set(String key, Object value, long expiry, Integer hashCode) {
return this.cacheProvider.set(key, value, new Date(expiry), hashCode);
}

@Override
public boolean set(String key, Object value, Integer hashCode) {
return this.cacheProvider.set(key, value, hashCode);
}


public MemCachedClient getCacheProvider() {
return cacheProvider;
}

public void setCacheProvider(MemCachedClient cacheProvider) {
this.cacheProvider = cacheProvider;
}

}

你可能感兴趣的:(memcached)