Exemple #1
0
    @Override
    public boolean shouldRemove(
        Entry<TileIndex, TileCacheEntry<T>> entry,
        Map<TileIndex, TileCacheEntry<T>> map,
        int suggestedMaxSize) {
      if (null == entry) {
        return false;
      } else if (null == entry.getValue()) {
        return true;
      } else {
        TileCacheEntry<T> value = entry.getValue();
        if (value.hasBeenRetrieved() || value.age() > _maxTileAge) {
          // This entry has been received, or is to old for us to
          // care; just remove it.
          return true;
        } else {
          // First see if there is anything which has already been
          // handled, so can be freely deleted.
          for (Pair<TileIndex, Long> hasData : _haveData) {
            TileIndex index = hasData.getFirst();
            TileCacheEntry<T> entryWithData = _cache.get(index);
            if (entryWithData.hasBeenRetrieved()) {
              _cache.remove(index);
              return false;
            }
          }

          // If we get this far, there was nothing already handled.
          //
          // See if there's anything so old we just don't care about
          // its safety any more.
          if (_orderedKeys.size() > 0) {
            TileIndex oldestKey = _orderedKeys.get(0);
            TileCacheEntry<T> oldestEntry = _cache.get(oldestKey);
            if (oldestEntry.age() > _maxTileAge) {
              _cache.remove(oldestKey);
            }
          }
          return false;
        }
      }
    }
Exemple #2
0
 @Override
 public int compare(Pair<TileIndex, Long> o1, Pair<TileIndex, Long> o2) {
   return -o1.getSecond().compareTo(o2.getSecond());
 }