Bug 569709 - Figure out the max number of entries we should store in the disk cache, and bump the default size of the disk cache to 250MB; r=jduell

This commit is contained in:
Ehsan Akhgari
2010-06-10 22:46:51 -04:00
parent 479d30d7d8
commit 72bafa14dd
4 changed files with 27 additions and 7 deletions

View File

@@ -294,14 +294,14 @@ nsDiskCacheMap::GetBucketRank(PRUint32 bucketIndex, PRUint32 targetRank)
nsresult
nsDiskCacheMap::GrowRecords()
{
if (mHeader.mRecordCount >= kMaxRecordCount)
if (mHeader.mRecordCount >= mMaxRecordCount)
return NS_OK;
CACHE_LOG_DEBUG(("CACHE: GrowRecords\n"));
// Resize the record array
PRUint32 newCount = mHeader.mRecordCount << 1;
if (newCount > kMaxRecordCount)
newCount = kMaxRecordCount;
PRInt32 newCount = mHeader.mRecordCount << 1;
if (newCount > mMaxRecordCount)
newCount = mMaxRecordCount;
nsDiskCacheRecord *newArray = (nsDiskCacheRecord *)
PR_REALLOC(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
if (!newArray)
@@ -1044,3 +1044,17 @@ nsDiskCacheMap::EnsureBuffer(PRUint32 bufSize)
}
return NS_OK;
}
void
nsDiskCacheMap::NotifyCapacityChange(PRUint32 capacity)
{
// Heuristic 1. average cache entry size is probably around 1KB
// Heuristic 2. we don't want more than 32MB reserved to store the record
// map in memory.
const PRInt32 RECORD_COUNT_LIMIT = 32 * 1024 * 1024 / sizeof(nsDiskCacheRecord);
PRInt32 maxRecordCount = PR_MIN(PRInt32(capacity), RECORD_COUNT_LIMIT);
if (mMaxRecordCount < maxRecordCount) {
// We can only grow
mMaxRecordCount = maxRecordCount;
}
}