memcache的配置:public class MemCacheInvoke {
protected static MemCachedClient mcc = new MemCachedClient(); static { // 设置缓存服务器列表,当使用分布式缓存的时,可以指定多个缓存服务器。
String[] servers = {"127.0.0.1:11211"}; // 设置服务器权重
Integer[] weights = {3, 2}; // 创建一个Socked连接池实例
SockIOPool pool = SockIOPool.getInstance(); // 向连接池设置服务器和权重
pool.setServers(servers);
pool.setWeights(weights); pool.setNagle(false);
pool.setSocketTO(3000);
pool.setSocketConnectTO(0);

pool.initialize();
}

public static MemCachedClient getInstance(){
return mcc; 
}
}

解决方案 »

  1.   

    这是 set/get/delete  cachepublic class PopCache {
    private MemCachedClient mcc = MemCacheInvoke.getInstance(); private static PopCache instance;
    private static Date EXPIRY_DATE = new Date(System.currentTimeMillis()+30*60*1000);
    protected PopCache() { } public static PopCache getInstance() {
    if (instance == null) {
    instance = new PopCache();
    }
    return instance;
    } public void put(String key, Map<Long, String> strmap) {
    if (strmap != null) {
    mcc.set(key, strmap, EXPIRY_DATE);
    }
    }
    public void replace(String key, Map<Long, String> strmap) {
    if (strmap != null) {
    mcc.replace(key, strmap, EXPIRY_DATE);
    }
    }
    public void delete(String key) {
    mcc.delete(key);
    } public Map<Long, String> get(String key) {
    try {
    Map<Long, String> strmap = (Map<Long, String>) mcc.get(key);
    return strmap;
    } catch (Exception e) {
    return null;
    } finally { }
    }


    }