@Override
  public void trim(MemoryTrimType trimType) {
    ArrayList<Entry<K, V>> oldLFUEntries;
    ArrayList<Entry<K, V>> oldMFUEntries;
    final double trimRatio = mCacheTrimStrategy.getTrimRatio(trimType);
    synchronized (this) {
      final int targetCacheSize = (int) (mCachedEntries.getSizeInBytes() * (1 - trimRatio));
      final int targetEvictionQueueSize = Math.max(0, targetCacheSize - getInUseSizeInBytes());
      int MFUTargetEvictionQueueSize = mMostFrequentlyUsedExclusiveEntries.getSizeInBytes();
      int LFUTargetEvictionQueueSize =
          Math.max(0, targetEvictionQueueSize - MFUTargetEvictionQueueSize);
      if (targetEvictionQueueSize <= MFUTargetEvictionQueueSize) {
        MFUTargetEvictionQueueSize = targetEvictionQueueSize;
        LFUTargetEvictionQueueSize = 0;
      }
      oldLFUEntries =
          trimExclusivelyOwnedEntries(
              Integer.MAX_VALUE,
              LFUTargetEvictionQueueSize,
              mLeastFrequentlyUsedExclusiveEntries,
              ArrayListType.LFU);
      oldMFUEntries =
          trimExclusivelyOwnedEntries(
              Integer.MAX_VALUE,
              MFUTargetEvictionQueueSize,
              mMostFrequentlyUsedExclusiveEntries,
              ArrayListType.MFU);
      makeOrphans(oldLFUEntries, oldMFUEntries);
    }
    maybeClose(oldLFUEntries, oldMFUEntries);
    maybeNotifyExclusiveEntriesRemoval(oldLFUEntries, oldMFUEntries);
    maybeUpdateCacheParams();
    maybeEvictEntries();
  }
Trims the cache according to the specified trimming strategy and the given trim type. We first
trim the LFU cache, if we need to trim more, we continue to trim the MFU cache.
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/AbstractAdaptiveCountingMemoryCache.java