Memcached的MemCachedClient设置过期时限

    public void testMemcache(){
        MemcacheUtil.set("abc","abc", new Date(1*10*1000));  
        MemcacheUtil.set("bbb","bbb", new Date(System.currentTimeMillis()+8000));  
        
          //大于2000为null             
          try {
            Thread.sleep(1*8*1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
                    
      System.out.println(MemcacheUtil.get("abc"));
      System.out.println(MemcacheUtil.get("bbb")); 
      try {
        Thread.sleep(1*1*1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      System.out.println(MemcacheUtil.get("abc"));
      System.out.println(MemcacheUtil.get("bbb")); 
    try {
        Thread.sleep(1*1*1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(MemcacheUtil.get("abc"));
    System.out.println(MemcacheUtil.get("bbb"));
    }

输出结果:

abc
null
abc
null
null
null


阅读更多
个人分类: Java
上一篇用Navicat连接Oracle数据库时报错ORA-28547:connection to server failed,probable Oracle Net admin error
下一篇VMware12.5 安装 苹果OS 问题总结
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭