public void clearStaleEntries() {
    List<K> expiredKeys = new ArrayList(128);
    Set<Map.Entry<K, CachedValue<V>>> entrySet = cache.entrySet();
    for (Map.Entry<K, CachedValue<V>> entry : entrySet) {
      CachedValue<V> cachedVal = entry.getValue();
      if (cachedVal.isExpired()) {
        expiredKeys.add(entry.getKey());
      }
    }
    for (K key : expiredKeys) {
      remove(key);
    }
  }