wininet: Implement sticky url cache entries.

This commit is contained in:
Juan Lang 2011-03-09 10:59:07 -08:00 committed by Alexandre Julliard
parent f7340864b9
commit 190acb9e26
2 changed files with 44 additions and 15 deletions

View File

@ -512,20 +512,16 @@ static void test_urlcacheA(void)
ret = CommitUrlCacheEntry(TEST_URL, NULL, filetime_zero, filetime_zero,
STICKY_CACHE_ENTRY, (LPBYTE)ok_header, strlen(ok_header), "html",
NULL);
todo_wine {
ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
SetLastError(0xdeadbeef);
ret = CommitUrlCacheEntry(TEST_URL, NULL, filetime_zero, filetime_zero,
NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
(LPBYTE)ok_header, strlen(ok_header), "html", NULL);
todo_wine {
ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
@ -545,7 +541,6 @@ static void test_urlcacheA(void)
ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
"expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
todo_wine
ok(lpCacheEntryInfo->dwExemptDelta == 86400,
"expected dwExemptDelta 864000, got %d\n",
lpCacheEntryInfo->dwExemptDelta);
@ -578,7 +573,6 @@ static void test_urlcacheA(void)
ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
"expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
todo_wine
ok(lpCacheEntryInfo->dwExemptDelta == 86400,
"expected dwExemptDelta 864000, got %d\n",
lpCacheEntryInfo->dwExemptDelta);

View File

@ -2473,6 +2473,11 @@ static BOOL CommitUrlCacheEntryInternal(
debugstr_w(lpszFileExtension),
debugstr_w(lpszOriginalUrl));
if (CacheEntryType & STICKY_CACHE_ENTRY && !lpszLocalFileName)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (lpszOriginalUrl)
WARN(": lpszOriginalUrl ignored\n");
@ -2612,7 +2617,13 @@ static BOOL CommitUrlCacheEntryInternal(
pUrlEntry->CacheDir = cDirectory;
pUrlEntry->CacheEntryType = CacheEntryType;
pUrlEntry->dwHeaderInfoSize = dwHeaderSize;
pUrlEntry->dwExemptDelta = 0;
if (CacheEntryType & STICKY_CACHE_ENTRY)
{
/* Sticky entries have a default exempt time of one day */
pUrlEntry->dwExemptDelta = 86400;
}
else
pUrlEntry->dwExemptDelta = 0;
pUrlEntry->dwHitRate = 0;
pUrlEntry->dwOffsetFileExtension = dwOffsetFileExtension;
pUrlEntry->dwOffsetHeaderInfo = dwOffsetHeader;
@ -2653,8 +2664,12 @@ static BOOL CommitUrlCacheEntryInternal(
{
if (pUrlEntry->CacheDir < pHeader->DirectoryCount)
pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles++;
pHeader->CacheUsage.QuadPart += file_size.QuadPart;
if (pHeader->CacheUsage.QuadPart > pHeader->CacheLimit.QuadPart)
if (CacheEntryType & STICKY_CACHE_ENTRY)
pHeader->ExemptUsage.QuadPart += file_size.QuadPart;
else
pHeader->CacheUsage.QuadPart += file_size.QuadPart;
if (pHeader->CacheUsage.QuadPart + pHeader->ExemptUsage.QuadPart >
pHeader->CacheLimit.QuadPart)
FIXME("file of size %s bytes fills cache\n", wine_dbgstr_longlong(file_size.QuadPart));
}
@ -3032,10 +3047,20 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName)
if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles)
pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--;
}
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
if (pUrlEntry->CacheEntryType & STICKY_CACHE_ENTRY)
{
if (pUrlEntry->size.QuadPart < pHeader->ExemptUsage.QuadPart)
pHeader->ExemptUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->ExemptUsage.QuadPart = 0;
}
else
pHeader->CacheUsage.QuadPart = 0;
{
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->CacheUsage.QuadPart = 0;
}
URLCache_DeleteEntry(pHeader, pEntry);
@ -3115,10 +3140,20 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName)
if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles)
pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--;
}
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
if (pUrlEntry->CacheEntryType & STICKY_CACHE_ENTRY)
{
if (pUrlEntry->size.QuadPart < pHeader->ExemptUsage.QuadPart)
pHeader->ExemptUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->ExemptUsage.QuadPart = 0;
}
else
pHeader->CacheUsage.QuadPart = 0;
{
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->CacheUsage.QuadPart = 0;
}
URLCache_DeleteEntry(pHeader, pEntry);