private void trimToSize(int maxSize) {
    while (mSize > maxSize && !mMap.isEmpty()) {
      Map.Entry<String, Bitmap> oldest =  mMap.entrySet().iterator().next();
      if (oldest == null) {
        break;
      }
      mMap.remove(oldest.getKey());
      mSize -= sizeOf(oldest.getValue());
    }
  }
Implementation of LRU cache (String to Bitmap) with a method to grab the oldest Bitmap.
tileview/src/main/java/com/moagrius/tileview/MemoryCache.java