예제 #1
0
 @Override
 public Object get(Object key) {
   // Check for null as Cache should not store null values / keys
   if (key == null) {
     throw new NullPointerException("key is null");
   }
   CacheValue cacheValue = map.get(key);
   // Check for null
   if (cacheValue == null) {
     return null;
   }
   // Check if to be autoexpired, autoExpireTimeInMs = 0 means expire immediately / no caching
   // Note: This point will never be reached if the value was put in cache when autoExpireTimeInMs
   // was 0
   if (this.autoExpireTimeInMs >= 0) {
     // Check if expired
     long now = new Date().getTime();
     if (cacheValue.getLastUpateTime() + this.autoExpireTimeInMs < now) {
       // Expired, remove
       remove(key);
       return null;
     }
   }
   // Not expired, return the value
   return cacheValue.getValue();
 }
예제 #2
0
  @Override
  public long getLastUpateTime(Object key) {
    // Check for null as Cache should not store null values / keys
    if (key == null) {
      throw new NullPointerException("key is null");
    }
    CacheValue value = map.get(key);

    if (value != null) {
      return value.getLastUpateTime();
    } else {
      return -1;
    }
  }