| title | IHttpCachePolicy::GetUserCachePolicy Method |
|---|---|
| description | Describes the IHttpCachePolicy::GetUserCachePolicy method and details its syntax, return value, remarks, code example, and requirements. |
| ms.date | 10/07/2016 |
| ms.assetid | 8d007e1a-16e6-ab44-bb60-7ce16e56f806 |
Returns the cache policy for the user.
virtual HTTP_CACHE_POLICY* GetUserCachePolicy(
VOID
) = 0; This method takes no parameters.
A pointer to an HTTP_CACHE_POLICY.
CHttpModule derived classes that register for request or response events receive an IHttpContext pointer as a parameter on the corresponding virtual method. Call the IHttpContext::GetResponse method, then the IHttpResponse::GetCachePolicy method, and finally the GetUserCachePolicy method to retrieve an HTTP_CACHE_POLICY pointer.
The GetUserCachePolicy return value depends on implementation. You should use the following information as a guideline, but it may not be correct in all scenarios:
The current default implementer of the IHttpCachePolicy interface declares a private``HTTP_CACHE_POLICY structure. During the construction of this implementer, the Policy member of this structure is set to HttpCachePolicyNocache, and the SecondsToLive member of this structure is set to 0. The GetUserCachePolicy method returns the address of this same HTTP_CACHE_POLICY structure.
IHttpCachePolicy implementers are responsible for memory management with this data; therefore, IHttpCachePolicy implementers that use dynamic memory allocation must release or call delete on the HTTP_CACHE_POLICY pointer when it is no longer needed.
IHttpCachePolicy implementers are responsible for memory management with this data; therefore, IHttpCachePolicy clients must not release or call delete on the returned HTTP_CACHE_POLICY pointer when this data is no longer needed.
The following code example demonstrates how to create a global module that listens for RQ_BEGIN_REQUEST and RQ_SEND_RESPONSE events. The module then retrieves an IHttpCachePolicy pointer and writes cache policy information for the user to the response stream.
[!code-cppIHttpCachePolicy#6]
For more information on how to create and deploy a native DLL module, see Walkthrough: Creating a Request-Level HTTP Module By Using Native Code.
The above code writes data that is similar to the following to the response stream:
Policy Type: HttpCachePolicyNocache
Seconds-to-Live: 0
You can optionally compile the code by using the __stdcall (/Gz) calling convention instead of explicitly declaring the calling convention for each function.
The GetUserCachePolicy method is thread safe. However, modifying the HTTP_CACHE_POLICY members independently is not thread safe because these members are public fields on a shared structure.
| Type | Description |
|---|---|
| Client | - IIS 7.0 on [!INCLUDEwinvista] - IIS 7.5 on Windows 7 - IIS 8.0 on Windows 8 - IIS 10.0 on Windows 10 |
| Server | - IIS 7.0 on [!INCLUDEwinsrv2008] - IIS 7.5 on Windows Server 2008 R2 - IIS 8.0 on Windows Server 2012 - IIS 8.5 on Windows Server 2012 R2 - IIS 10.0 on Windows Server 2016 |
| Product | - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0 - [!INCLUDEiisexp75], [!INCLUDEiisexp80], [!INCLUDEiisexp100] |
| Header | Httpserv.h |