void BlobCache::clean() { // Remove a random cache entry until the total cache size gets below half // the maximum total cache size. while (mTotalSize > mMaxTotalSize / 2) { size_t i = size_t(blob_random() % (mCacheEntries.size())); const CacheEntry& entry(mCacheEntries[i]); mTotalSize -= entry.getKey()->getSize() + entry.getValue()->getSize(); mCacheEntries.removeAt(i); } }
size_t BlobCache::findVictim() { switch (mPolicySelect) { case Select::RANDOM: return size_t(blob_random() % (mCacheEntries.size())); case Select::LRU: return std::min_element(mCacheEntries.begin(), mCacheEntries.end(), [](const CacheEntry &a, const CacheEntry &b) { return a.getRecency() < b.getRecency(); }) - mCacheEntries.begin(); default: ALOGE("findVictim: unknown mPolicySelect: %d", mPolicySelect); return 0; } }