public Cache put(String host,InetAddress[] addresses){
  int policy=getPolicy();
  if (policy == InetAddressCachePolicy.NEVER) {
    return this;
  }
  if (policy != InetAddressCachePolicy.FOREVER) {
    LinkedList<String> expired=new LinkedList<>();
    long now=System.currentTimeMillis();
    for (    String key : cache.keySet()) {
      CacheEntry entry=cache.get(key);
      if (entry.expiration >= 0 && entry.expiration < now) {
        expired.add(key);
      }
 else {
        break;
      }
    }
    for (    String key : expired) {
      cache.remove(key);
    }
  }
  long expiration;
  if (policy == InetAddressCachePolicy.FOREVER) {
    expiration=-1;
  }
 else {
    expiration=System.currentTimeMillis() + (policy * 1000);
  }
  CacheEntry entry=new CacheEntry(addresses,expiration);
  cache.put(host,entry);
  return this;
}

public Cache put ( String host , InetAddress [ ] addresses ) { int policy = getPolicy ( ) ; if ( policy == InetAddressCachePolicy . NEVER ) { return this ; } if ( policy != InetAddressCachePolicy . FOREVER ) { LinkedList < String > expired = new LinkedList < > ( ) ; long now = System . currentTimeMillis ( ) ; for ( String key : cache . keySet ( ) ) { CacheEntry entry = cache . get ( key ) ; if ( entry . expiration >= 0 && entry . expiration < now ) { expired . add ( key ) ; } else { break ; } } for ( String key : expired ) { cache . remove ( key ) ; } } long expiration ; if ( policy == InetAddressCachePolicy . FOREVER ) { expiration = - 1 ; } else { expiration = System . currentTimeMillis ( ) + ( policy * 1000 ) ; } CacheEntry entry = new CacheEntry ( addresses , expiration ) ; cache . put ( host , entry ) ; return this ; }
add an entry to the cache . if there ' s already an entry then for this host then the entry will be replaced .
