Cache学习系列一

来源:互联网 发布:深圳大学有网络教育吗 编辑:程序博客网 时间:2024/06/06 09:58

1:新建Cache

 

 

例子如下:行为如下.

public class CacheManager{

 private staic HashMap casheMap = new HashMap();

 

  pubic CacheManager(){

  }

  private synchronized static Cache getCache(String key){

  return (Cache)cacheMap.get(lkey);

  }

 

 

  private synchronized static boolean hasCache(String key){

     return cacheMap.containsKey(key);

   }

 

  public synchronized static void invalidateAll(){

   cacheMap.clear();

  }

 

  public synchronized static void invalidate(String key){

   cacheMap.remove(key);

  }

 

  public synchronized static void putCache(String key,Cache object){

    cacheMap.put(key,object);

   }

 

  public static Cache getContent(String key){

   if(hasCache(key)){

      Cache cache = getCache(key);

       if(cacheExpired(cache)){

         cache.setExpired(true);

        }

         return cache;

 

     }

 

 

   public static void putContent(String key,Object content,long ttl){

    //把要用cache存储的Cache对象保存到Cache中去.

   }

 

   private static boolean cacheExpired(Cache cache){

    //判断cache是否timeOut

   }

}

 

 

 

原创粉丝点击