下面是DiskBasedCache#pruneIfNeeded()源码:
private
void
pruneIfNeeded(
int
neededSpace) {
if
((mTotalSize + neededSpace) < mMaxCacheSizeInBytes) {
return
;
}
long
before = mTotalSize;
int
prunedFiles =
0
;
long
startTime = SystemClock.elapsedRealtime();
Iterator<map.entry<string, cacheheader=
""
>> iterator = mEntries.entrySet().iterator();
while
(iterator.hasNext()) {
Map.Entry<string, cacheheader=
""
> entry = iterator.next();
CacheHeader e = entry.getValue();
boolean
deleted = getFileForKey(e.key).delete();
if
(deleted) {
mTotalSize -= e.size;
}
else
{
}
iterator.remove();
prunedFiles++;
&nbs