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

3 篇文章 0 订阅
  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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值