Brought to you by the |
This section describes the functions used by clients that need persistent caching services. The functions allow an application to save data in the local file system for subsequent use, such as in situations where access to the data is over a low bandwidth link, or the access is not available at all. The calling program that inserts data into the persistent cache assigns a source name that is used to do operations such as retrieve the data, set and get some properties on it, and delete it.
The protocols implemented in Win32 Internet functions use the cache functions to provide persistent caching and off-line browsing. Unless explicitly specified not to cache through the INTERNET_FLAG_NO_CACHE_WRITE flag, Win32 Internet functions cache all data downloaded from the network. The responses to POST data are not cached.
The cache may contain variable size information for each URL stored. This is reflected in the INTERNET_CACHE_ENTRY_INFO structure. When the cache functions return this structure, they create a buffer that is always the size of INTERNET_CACHE_ENTRY_INFO plus any variable-size information. If a pointer member is not NULL, it points to the memory area immediately after the structure. While copying the returned buffer from a function into another buffer, the pointer members should be fixed to point to the appropriate place in the new buffer, as the following example shows:
lpDstCEInfo->lpszSourceUrlName = (LPINTERNET_CACHE_ENTRY_INFO) ((LPBYTE) lpSrcCEInfo + ((DWORD) (lpOldCEInfo->lpszSourceUrlName) - (DWORD) lpOldCEInfo))
Some cache functions fail with the ERROR_INSUFFICIENT_BUFFER error value if you specify a buffer that is too small to contain the cache-entry information retrieved by the function. In this case, the function also returns the required size of the buffer. You can then allocate a buffer of the appropriate size and call the function again. If you want the function to succeed on the first call, allocate a buffer of the size specified by the MAX_CACHE_ENTRY_INFO_SIZE value, and then set the dwStructSize member of the INTERNET_CACHE_ENTRY_INFO structure to MAX_CACHE_ENTRY_INFO_SIZE when calling the function.
BOOL CommitUrlCacheEntry( IN LPCSTR lpszUrlName, IN LPCTSTR lpszLocalFileName, IN FILETIME ExpireTime, IN FILETIME LastModifiedTime, IN DWORD CacheEntryType, IN LPCBYTE lpHeaderInfo, IN DWORD dwHeaderSize, IN LPCTSTR lpszFileExtension, IN DWORD dwReserved );
Caches data in the specified file in the cache storage and associates it with the given URL.
Value | Meaning |
ERROR_FILE_NOT_FOUND | The specified local file is not found. |
ERROR_DISK_FULL | The cache storage is full. |
If the cache storage is full, the function invokes cache cleanup to make space for this new file. If the file size is bigger than the cache size, the function returns ERROR_DISK_FULL. If the cache entry already exists, the function overwrites the entry. The user could specify SPARSE_CACHE_ENTRY in the Commit to indicate that the size of the data is incomplete.
BOOL CreateUrlCacheEntry( IN LPCSTR lpszUrlName, IN DWORD dwExpectedFileSize, IN DWORD lpszFileExtension, OUT LPTSTR lpszFileName, IN DWORD dwReserved );
Allocates requested cache storage, and creates a local file name for saving the cache entry corresponding to the source name.
Internet services that use the cache should call this function to write directly into the cache storage. The caller should indicate the expected size of the file, but it is not guaranteed. Once the file is completely received, the caller should call CommitUrlCacheEntry to commit the entry in the cache.
BOOL GetUrlCacheEntryInfo( IN LPCSTR lpszUrlName, IN LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo, IN OUT LPDWORD lpdwCacheEntryInfoBufferSize );
Retrieves information about a cache entry.
Value | Meaning |
ERROR_INSUFFICIENT_BUFFER | The size of lpCacheEntryInfo as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information. |
ERROR_FILE_NOT_FOUND | The specified cache entry is not found in the cache. |
BOOL ReadUrlCacheEntryStream( IN HANDLE hUrlCacheStream, IN DWORD dwLocation, IN OUT LPVOID lpBuffer, IN OUT LPDWORD lpdwLen, IN DWORD dwReserved );
Reads the cached data from a stream that has been opened using the RetrieveUrlCacheEntryStream function.
BOOL RetrieveUrlCacheEntryFile( IN LPCSTR lpszUrlName, OUT LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo, IN OUT LPDWORD lpdwCacheEntryInfoBufferSize IN DWORD dwReserved );
Retrieves a cache entry from the cache in the form of a file.
Value | Meaning |
ERROR_FILE_NOT_FOUND | The cache entry specified by the source name is not found in the cache storage. |
ERROR_INSUFFICIENT_BUFFER | The size of the lpCacheEntryInfo buffer as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to get all the information. |
If an extension was provided while calling CommitUrlCacheEntry, the file will have the specified extension. If the entry is not available in the cache, this function returns ERROR_FILE_NOT_FOUND; otherwise, it returns the name of the local file. The caller is given only read permission to the local file, so the caller should not attempt to write or delete the file.
The file is locked for the caller when it is retrieved; the caller should unlock the file after it has been used up. The cache manager will automatically unlock the locked files after a certain interval. While the file is locked, the cache manager will not remove the file from the cache. It is important to note that this function may be efficient or expensive, depending on the internal implementation of the cache. For instance, if the URL data is stored in a packed file that contains data for other URLs, the cache will make a copy of the data to a file in a temporary directory maintained by the cache. The cache will eventually delete the copy. It is recommended that this function be used only in situations where a file name is needed to launch an application. RetrieveUrlCacheEntryStream and associated stream functions should be used in most cases.
HANDLE RetrieveCacheEntryStream( IN LPCSTR lpszUrlName, OUT LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo, IN OUT LPDWORD lpdwCacheEntryInfoBufferSize, IN BOOL fRandomRead, IN DWORD dwReserved );
Provides the most efficient and implementation-independent way of accessing the cache data.
Value | Meaning |
ERROR_FILE_NOT_FOUND | The cache entry specified by the source name is not found in the cache storage. |
ERROR_INSUFFICIENT_BUFFER | The size of lpCacheEntryInfo as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information. |
Cache clients that do not need URL data in the form of a file should use this function to access the data for a particular URL.
BOOL SetUrlCacheEntryInfo( IN LPCSTR lpszUrlName, IN LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo, IN DWORD dwFieldControl );
Sets the specified members of the INTERNET_CACHE_ENTRY_INFO structure.
Value | Meaning |
ERROR_FILE_NOT_FOUND | The specified cache entry is not found in the cache. |
ERROR_INVALID_PARAMETER | The value(s) to be set is invalid. |
CACHE_ENTRY_ATTRIBUTE_FC | |
CACHE_ENTRY_HITRATE_FC | |
CACHE_ENTRY_MODTIME_FC | |
CACHE_ENTRY_EXPTIME_FC | |
CACHE_ENTRY_ACCTIME_FC | |
CACHE_ENTRY_SYNCTIME_FC | |
CACHE_ENTRY_HEADERINFO_FC |
The last two flags have not been implemented in this release.
BOOL UnlockUrlCacheEntryFile( IN LPCSTR lpszUrlName, IN DWORD dwReserved );
Unlocks the cache entry that was locked while the file was retrieved for use from the cache.
The application should not access the file after calling this function.
When this function returns, the cache manager is free to delete the cache entry.
BOOL UnlockUrlCacheEntryStream( IN HANDLE hUrlCacheStream, IN DWORD dwReserved );
Closes the stream that has been retrieved using the RetrieveUrlCacheEntryStream function.
See also RetrieveUrlCacheEntryStream
BOOL DeleteUrlCacheEntry( IN LPCSTR lpszUrlName );
Removes the file associated with the source name from the cache, if the file exists.
Value | Meaning |
ERROR_FILE_NOT_FOUND | The file is not in the cache. |
ERROR_ACCESS_DENIED | The file is in use. |
BOOL FindCloseUrlCache( IN HANDLE hEnumHandle );
Closes the specified enumeration handle.
See also FindFirstUrlCacheEntry
HANDLE FindFirstUrlCacheEntry ( IN LPCSTR lpszUrlSearchPattern, OUT LPINTERNET_CACHE_ENTRY_INFO lpFirstCacheEntryInfo, IN OUT LPDWORD lpdwFirstCacheEntryInfoBufferSize );
Begins the enumeration of the cache.
This function and the FindNextUrlCacheEntry function return variable size information. In order to not have the enumeration terminate due to ERROR_INSUFFICIENT_BUFFER, an application should create one buffer of the size specified by the MAX_CACHE_ENTRY_INFO_SIZE value, and pass the address of the buffer repeatedly to all the enumeration functions. After the function succeeds, another buffer may be used of the size returned by lpdwCacheEntryInfoBufferSize to keep the returned information. Be careful to fix the pointer elements while copying the buffer.
See also FindNextUrlCacheEntry
BOOL FindNextUrlCacheEntry( IN HANDLE hEnumHandle, OUT LPINTERNET_CACHE_ENTRY_INFO lpNextCacheEntryInfo, IN OUT LPWORD lpdwNextCacheEntryInfoBufferSize );
Retrieves the next entry in the cache.
Value | Meaning |
ERROR_NO_MORE_FILES | The enumeration completed. |
ERROR_INSUFFICIENT_BUFFER | The size of lpCacheEntryInfo as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information. |
See also FindFirstUrlCacheEntry