forked from mirrors/gecko-dev
Bug 1893402 - Part 2: Use minimum cache expiration time in image cache. r=tnikkel
Differential Revision: https://phabricator.services.mozilla.com/D208979
This commit is contained in:
parent
6ee82f702f
commit
a127747b14
3 changed files with 25 additions and 11 deletions
|
|
@ -66,9 +66,23 @@ class imgCacheEntry {
|
|||
void UpdateLoadTime();
|
||||
|
||||
uint32_t GetExpiryTime() const { return mExpiryTime; }
|
||||
void SetExpiryTime(uint32_t aExpiryTime) {
|
||||
mExpiryTime = aExpiryTime;
|
||||
Touch();
|
||||
void AccumulateExpiryTime(uint32_t aExpiryTime, bool aForceTouch = false) {
|
||||
// 0 means "doesn't expire".
|
||||
// Otherwise, calculate the minimum value.
|
||||
if (aExpiryTime == 0) {
|
||||
if (aForceTouch) {
|
||||
Touch();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mExpiryTime == 0 || aExpiryTime < mExpiryTime) {
|
||||
mExpiryTime = aExpiryTime;
|
||||
Touch();
|
||||
} else {
|
||||
if (aForceTouch) {
|
||||
Touch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GetMustValidate() const { return mMustValidate; }
|
||||
|
|
|
|||
|
|
@ -579,9 +579,9 @@ void imgRequest::UpdateCacheEntrySize() {
|
|||
}
|
||||
|
||||
void imgRequest::SetCacheValidation(imgCacheEntry* aCacheEntry,
|
||||
nsIRequest* aRequest) {
|
||||
/* get the expires info */
|
||||
if (!aCacheEntry || aCacheEntry->GetExpiryTime() != 0) {
|
||||
nsIRequest* aRequest,
|
||||
bool aForceTouch /* = false */) {
|
||||
if (!aCacheEntry) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -605,7 +605,7 @@ void imgRequest::SetCacheValidation(imgCacheEntry* aCacheEntry,
|
|||
info.mExpirationTime.emplace(nsContentUtils::SecondsFromPRTime(PR_Now()) -
|
||||
1);
|
||||
}
|
||||
aCacheEntry->SetExpiryTime(*info.mExpirationTime);
|
||||
aCacheEntry->AccumulateExpiryTime(*info.mExpirationTime, aForceTouch);
|
||||
// Cache entries default to not needing to validate. We ensure that
|
||||
// multiple calls to this function don't override an earlier decision to
|
||||
// validate by making validation a one-way decision.
|
||||
|
|
@ -690,7 +690,7 @@ imgRequest::OnStartRequest(nsIRequest* aRequest) {
|
|||
}
|
||||
}
|
||||
|
||||
SetCacheValidation(mCacheEntry, aRequest);
|
||||
SetCacheValidation(mCacheEntry, aRequest, /* aForceTouch = */ true);
|
||||
|
||||
// Shouldn't we be dead already if this gets hit?
|
||||
// Probably multipart/x-mixed-replace...
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ class imgRequest final : public nsIThreadRetargetableStreamListener,
|
|||
|
||||
// Set the cache validation information (expiry time, whether we must
|
||||
// validate, etc) on the cache entry based on the request information.
|
||||
// If this function is called multiple times, the information set earliest
|
||||
// wins.
|
||||
static void SetCacheValidation(imgCacheEntry* aEntry, nsIRequest* aRequest);
|
||||
// If this function is called multiple times, the most strict value wins.
|
||||
static void SetCacheValidation(imgCacheEntry* aEntry, nsIRequest* aRequest,
|
||||
bool aForceTouch = false);
|
||||
|
||||
bool GetMultipart() const;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue