@GuardedBy("mLock")
  private boolean maybeUpdateFileCacheSizeAndIndex() {
    long size = 0;
    int count = 0;
    boolean foundFutureTimestamp = false;
    int numFutureFiles = 0;
    int sizeFutureFiles = 0;
    long maxTimeDelta = -1;
    long now = mClock.now();
    long timeThreshold = now + FUTURE_TIMESTAMP_THRESHOLD_MS;
    Set<String> tempResourceIndex;
    if (mIndexPopulateAtStartupEnabled && mResourceIndex.isEmpty()) {
      tempResourceIndex = mResourceIndex;
    } else if (mIndexPopulateAtStartupEnabled) {
      tempResourceIndex = new HashSet<>();
    } else {
      tempResourceIndex = null;
    }
    try {
      Collection<DiskStorage.Entry> entries = mStorage.getEntries();
      for (DiskStorage.Entry entry : entries) {
        count++;
        size += entry.getSize();

        // Check if any files have a future timestamp, beyond our threshold
        if (entry.getTimestamp() > timeThreshold) {
          foundFutureTimestamp = true;
          numFutureFiles++;
          sizeFutureFiles += entry.getSize();
          maxTimeDelta = Math.max(entry.getTimestamp() - now, maxTimeDelta);
        } else if (mIndexPopulateAtStartupEnabled) {
          Preconditions.checkNotNull(tempResourceIndex);
          tempResourceIndex.add(entry.getId());
        }
      }
      if (foundFutureTimestamp) {
        mCacheErrorLogger.logError(
            CacheErrorLogger.CacheErrorCategory.READ_INVALID_ENTRY,
            TAG,
            "Future timestamp found in "
                + numFutureFiles
                + " files , with a total size of "
                + sizeFutureFiles
                + " bytes, and a maximum time delta of "
                + maxTimeDelta
                + "ms",
            null);
      }
      if (mCacheStats.getCount() != count || mCacheStats.getSize() != size) {
        if (mIndexPopulateAtStartupEnabled && mResourceIndex != tempResourceIndex) {
          Preconditions.checkNotNull(tempResourceIndex);
          mResourceIndex.clear();
          mResourceIndex.addAll(tempResourceIndex);
        }
        mCacheStats.set(size, count);
      }
    } catch (IOException ioe) {
      mCacheErrorLogger.logError(
          CacheErrorLogger.CacheErrorCategory.GENERIC_IO,
          TAG,
          "calcFileCacheSize: " + ioe.getMessage(),
          ioe);
      return false;
    }
    mCacheSizeLastUpdateTime = now;
    return true;
  }
If file cache size is not calculated or if it was calculated a long time ago
(FILECACHE_SIZE_UPDATE_PERIOD_MS) recalculated from file listing.

@return true if it was recalculated, false otherwise.
imagepipeline-base/src/main/java/com/facebook/cache/disk/DiskStorageCache.java