public Memcache createMemcacheClient() throws Exception {
    String poolName = getPoolName();

    // grab an instance of our connection pool
    SockIOPool pool = SockIOPool.getInstance(poolName);

    // set the servers and the weights
    pool.setServers(getServers());
    pool.setWeights(getWeights());

    // set some basic pool settings
    pool.setInitConn(getInitConn());
    pool.setMinConn(getMinConn());
    pool.setMaxConn(getMaxConn());
    pool.setMaxIdle(getMaxIdle());

    // set the sleep for the maint thread
    // it will wake up every x seconds and
    // maintain the pool size
    pool.setMaintSleep(getMaintSleep());

    // set some TCP settings
    pool.setNagle(false);
    pool.setSocketTO(getSocketTimeout());
    pool.setSocketConnectTO(getSocketConnectTimeout());

    // initialize the connection pool
    pool.initialize();

    MemCachedClient client = new MemCachedClient(getClassLoader(), getErrorHandler(), poolName);
    client.setCompressEnable(isCompressEnable());
    client.setDefaultEncoding(getDefaultEncoding());

    return new DangaMemcache(client, poolName);
  }
Exemplo n.º 2
0
  /**
   * 添加一个指定的值到缓存中.
   *
   * @param key
   * @param value
   * @return
   */
  public boolean add(String key, Object value) {
    if (log.isDebugEnabled()) {
      log.debug("have added a pojo to cache : key is " + key);
    }

    return mcc.set(key, value);
  }
Exemplo n.º 3
0
  /**
   * 根据指定的关键字获取对象.
   *
   * @param key
   * @return
   */
  public Object get(String key) {
    if (log.isDebugEnabled()) {
      log.debug("have gotten a pojo to cache : key is " + key);
    }

    return mcc.get(key);
  }
Exemplo n.º 4
0
  public boolean delete(String key) {

    if (log.isDebugEnabled()) {
      log.debug("have deleted a pojo to cache : key is " + key);
    }

    return mcc.delete(key);
  }
Exemplo n.º 5
0
  public boolean replace(String key, Object value) {

    if (log.isDebugEnabled()) {
      log.debug("have replaced a pojo to cache : key is " + key);
    }

    return mcc.replace(key, value);
  }
Exemplo n.º 6
0
  public static MemCachedClient getClient() {
    MemCachedClient client = new MemCachedClient(true);

    client.setTransCoder(new StringTransCoder());

    SchoonerSockIOPool pool = SchoonerSockIOPool.getInstance();
    pool.setServers(new String[] {"localhost:11211"});

    pool.setInitConn(5);
    pool.setMinConn(5);
    pool.setMaxConn(10);
    pool.setMaintSleep(0);
    pool.setNagle(false);

    pool.initialize();

    return client;
  }
Exemplo n.º 7
0
  public boolean replace(String key, Object value, Date expiry) {

    if (log.isDebugEnabled()) {
      log.debug(
          "have replaced a pojo to cache : key is " + key + ";expiryDate is " + expiry.toString());
    }

    return mcc.replace(key, value, expiry);
  }
Exemplo n.º 8
0
 /**
  * 根据指定一批Key批量获取缓存内容。
  *
  * @param sKeys 指定的一批Key。
  * @return Map<sKey, oValue>
  */
 public Map<String, Object> getMulti(String[] sKeys) {
   return mcc.getMulti(sKeys);
 }
Exemplo n.º 9
0
 // 检测Cache中当前Key是否存在
 public boolean exists(String key) {
   return mcc.keyExists(key);
 }