Compartir a través de


Enumerating the Cache

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The FindFirstUrlCacheEntry and FindNextUrlCacheEntry functions enumerate the data stored in the cache. FindFirstUrlCacheEntry starts the enumeration by taking a search pattern, a buffer, and a buffer size to create a handle and return the first cache entry. FindNextUrlCacheEntry takes the handle created by FindFirstUrlCacheEntry, a buffer, and a buffer size to return the next cache entry.

Both functions store an INTERNET_CACHE_ENTRY_INFO structure in the buffer. The size of this structure varies for each entry. If the buffer size passed to either function is insufficient, the function fails, and GetLastError returns ERROR_INSUFFICIENT_BUFFER. The buffer size variable contains the buffer size that was needed to retrieve that cache entry. A buffer of the size indicated by the buffer size variable should be allocated, and the function should be called again with the new buffer.

INTERNET_CACHE_ENTRY_INFO contains the structure size; URL of the cached data; local file name; cache entry type; use count; hit rate; size; last modified, expire, last access, and last synchronized times; header data and header data size; and file extension.

FindFirstUrlCacheEntry takes a search pattern, a buffer that stores the INTERNET_CACHE_ENTRY_INFO structure, and the buffer size. Currently, only the default search pattern, which returns all cache entries, is implemented.

After the cache is enumerated, the application should call FindCloseUrlCache to close the cache enumeration handle.

The following code example uses FindFirstUrlCacheEntry to initiate the enumeration process.

#define CACHE_ENTRY_BUFFER_SIZE  (1024*5)
DWORD dwBufferSize;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry;
HANDLE hCacheDir;
//Allocate memory for the buffer that stores .
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO)LocalAlloc(LPTR,CACHE_ENTRY_BUFFER_SIZE);
//Set the buffer size.
dwBufferSize = CACHE_ENTRY_BUFFER_SIZE;
//Call  to return a handle to the cache.
hCacheDir = FindFirstUrlCacheEntry(NULL,lpCacheEntry,&dwBufferSize);

The following code example shows how to retrieve the next cache entry by calling FindNextUrlCacheEntry and passing the cache entry handle returned by FindFirstUrlCacheEntry.

BOOL bValue = FindNextUrlCacheEntry(hCacheDir,lpCacheEntry, &dwBufferSize);

The following code example shows how to release the cache handle returned by FindFirstUrlCacheEntry.

FindCloseUrlCache(hCacheDir);

See Also

Concepts

Caching