spring配置
Xml代码
- <?xml version="1.0" encoding="UTF-8"?>
- <beans
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd ">
- <!--memcached 客户端***start-->
- <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
- <constructor-arg>
- <value>neeaMemcachedPool</value>
- </constructor-arg>
- <property name="servers">
- <list>
- <value>192.168.54.207:12345</value>
- <!--多服务器
- <value>
- 192.168.54.207:12346
- </value>
- -->
- </list>
- </property>
- <!--多服务器负载均衡-->
- <!--<property name="weights">
- <value>5,5</value>
- </property>-->
- <property name="initConn">
- <value>20</value>
- </property>
- <property name="minConn">
- <value>10</value>
- </property>
- <property name="maxConn">
- <value>500</value>
- </property>
- <property name="maintSleep">
- <value>30</value>
- </property>
- <property name="nagle">
- <value>false</value>
- </property>
- <property name="maxIdle">
- <value>6000</value>
- </property>
- <property name="socketTO">
- <value>3000</value>
- </property>
- </bean>
- <!--memcached client-->
- <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">
- <constructor-arg>
- <value>neeaMemcachedPool</value>
- </constructor-arg>
- <property name="compressEnable">
- <value>true</value>
- </property>
- <property name="compressThreshold">
- <value>4096</value>
- </property>
- </bean>
- <!--memcached 客户端***end-->
- <!--如果换客户端或者换缓存了,在web.mxl里切换加载对应的配置文件即可-->
- <bean id="cache" class="com.xxx.CacheClientImpl">
- <property name="cacheProvider" ref="memcachedClient"/>
- </bean>
- </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;
}
}