uint64_t getCounter() REQUIRES(mMutex) {
static uint64_t counter = 0;
return counter++;
}
getCounter()
维护 counter
,它表示缓存的使用次序,用于 LRU 清除缓存。
void evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
auto itr = mBuffers.begin();
uint64_t minCounter = itr->second;
auto minBuffer = itr;
itr++;
while (itr != mBuffers.end()) {
uint64_t counter = itr->second;
if (counter < minCounter) {
minCounter = counter;
minBuffer = itr;
}
itr++;
}
uncacheLocked(minBuffer->first);
}