spring 管理 memcached

spring配置

Xml代码

  1. <?xml version="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. <bean id="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.     <property name="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.     <!--<property name="weights">  
  24.         <value>5,5</value>  
  25.     </property>-->  
  26.     <property name="initConn">  
  27.         <value>20</value>  
  28.     </property>  
  29.     <property name="minConn">  
  30.         <value>10</value>  
  31.     </property>  
  32.     <property name="maxConn">  
  33.         <value>500</value>  
  34.     </property>  
  35.     <property name="maintSleep">  
  36.         <value>30</value>  
  37.     </property>  
  38.     <property name="nagle">  
  39.         <value>false</value>  
  40.     </property>  
  41.     <property name="maxIdle">  
  42.         <value>6000</value>  
  43.     </property>  
  44.     <property name="socketTO">  
  45.         <value>3000</value>  
  46.     </property>  
  47. </bean>  
  48.   
  49. <!--memcached client-->  
  50. <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">  
  51.     <constructor-arg>  
  52.         <value>neeaMemcachedPool</value>  
  53.     </constructor-arg>  
  54.     <property name="compressEnable">  
  55.         <value>true</value>  
  56.     </property>  
  57.     <property name="compressThreshold">  
  58.         <value>4096</value>  
  59.     </property>  
  60. </bean>  
  61. <!--memcached 客户端***end-->  
  62.   
  63. <!--如果换客户端或者换缓存了,在web.mxl里切换加载对应的配置文件即可-->  
  64. <bean id="cache" class="com.xxx.CacheClientImpl">  
  65.     <property name="cacheProvider" ref="memcachedClient"/>  
  66. </bean>  
  67.   
  68. </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;
 }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值