JAVA缓存的实现(2)(转自其他地方)

来源:互联网 发布:网络监控技术 编辑:程序博客网 时间:2024/06/07 22:57
  1. package lhm.hcy.guge.frameset.cache;   
  2.   
  3. /**  
  4.  * <p>Title: </p>  
  5.  *  
  6.  * <p>Description: 缓存DTO</p>  
  7.  *  
  8.  * <p>Copyright: Copyright (c) 2008</p>  
  9.  *  
  10.  * <p>Company: </p>  
  11.  *  
  12.  * @author Deepblue  2008-11-11  
  13.  * @version 1.0  
  14.  */  
  15. public class Cache {   
  16.         private String key;//缓存ID   
  17.         private Object value;//缓存数据   
  18.         private long timeOut;//更新时间   
  19.         private boolean expired; //是否终止   
  20.         public Cache() {   
  21.                 super();   
  22.         }   
  23.   
  24.         public Cache(String key, Object value, long timeOut, boolean expired) {   
  25.                 this.key = key;   
  26.                 this.value = value;   
  27.                 this.timeOut = timeOut;   
  28.                 this.expired = expired;   
  29.         }   
  30.   
  31.         public String getKey() {   
  32.                 return key;   
  33.         }   
  34.   
  35.         public long getTimeOut() {   
  36.                 return timeOut;   
  37.         }   
  38.   
  39.         public Object getValue() {   
  40.                 return value;   
  41.         }   
  42.   
  43.         public void setKey(String string) {   
  44.                 key = string;   
  45.         }   
  46.   
  47.         public void setTimeOut(long l) {   
  48.                 timeOut = l;   
  49.         }   
  50.   
  51.         public void setValue(Object object) {   
  52.                 value = object;   
  53.         }   
  54.   
  55.         public boolean isExpired() {   
  56.                 return expired;   
  57.         }   
  58.   
  59.         public void setExpired(boolean b) {   
  60.                 expired = b;   
  61.         }   
  62. }   
  63.   
  64. //测试类,   
  65. class Test {   
  66.     public static void main(String[] args) {   
  67.         System.out.println(CacheManager.getSimpleFlag("alksd"));   
  68. //        CacheManager.putCache("abc", new Cache());   
  69. //        CacheManager.putCache("def", new Cache());   
  70. //        CacheManager.putCache("ccc", new Cache());   
  71. //        CacheManager.clearOnly("");   
  72. //        Cache c = new Cache();   
  73. //        for (int i = 0; i < 10; i++) {   
  74. //            CacheManager.putCache("" + i, c);   
  75. //        }   
  76. //        CacheManager.putCache("aaaaaaaa", c);   
  77. //        CacheManager.putCache("abchcy;alskd", c);   
  78. //        CacheManager.putCache("cccccccc", c);   
  79. //        CacheManager.putCache("abcoqiwhcy", c);   
  80. //        System.out.println("删除前的大小:"+CacheManager.getCacheSize());   
  81. //        CacheManager.getCacheAllkey();   
  82. //        CacheManager.clearAll("aaaa");   
  83. //        System.out.println("删除后的大小:"+CacheManager.getCacheSize());   
  84. //        CacheManager.getCacheAllkey();   
  85.   
  86.   
  87.     }   
  88. }  
0 0
原创粉丝点击