Disables the kernel cache for this response.
virtual VOID DisableKernelCache(
ULONG reason = 9
) = 0;
- reason
The optional reason for disabling the kernel cache.
VOID.
The DisableKernelCache method disables kernel caching for the current response.
You can optionally pass a reason parameter that contains a value defined in the IISCacheEvents::HTTPSYS_CACHEABLE::enumReason enumeration to indicate why you are disabling caching.
Note: |
|---|
If you do not pass a reason parameter to the DisableKernelCache method, the default value of 9 (HANDLER_HTTPSYS_UNFRIENDLY) will be used. |
The following code example demonstrates how to use the DisableKernelCache method to disable kernel caching for the current request.
Note: |
|---|
Combine this example module with the example module listed for the GetKernelCacheEnabled method if you want to return the current caching status. |
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Retrieve a pointer to the response.
IHttpResponse * pHttpResponse = pHttpContext->GetResponse();
// Test for an error.
if (pHttpResponse != NULL)
{
// Disable caching as HANDLER_HTTPSYS_UNFRIENDLY.
pHttpResponse->DisableKernelCache(9);
}
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
};
// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
UNREFERENCED_PARAMETER( pAllocator );
// Create a new instance.
MyHttpModule * pModule = new MyHttpModule;
// Test for an error.
if (!pModule)
{
// Return an error if the factory cannot create the instance.
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
else
{
// Return a pointer to the module.
*ppModule = pModule;
pModule = NULL;
// Return a success status.
return S_OK;
}
}
void Terminate()
{
// Remove the class from memory.
delete this;
}
};
// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
UNREFERENCED_PARAMETER( pGlobalInfo );
// Set the request notifications and exit.
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST,
0
);
}
Your module must export the RegisterModule function. You can export this function by creating a module definition (.def) file for your project, or you can compile the module by using the /EXPORT:RegisterModule switch. For more information, see Walkthrough: Creating a Request-Level HTTP Module By Using Native Code [IIS 7].
You can optionally compile the code by using the __stdcall (/Gz) calling convention instead of explicitly declaring the calling convention for each function.
Type | Description |
|---|
Client | Requires IIS 7 on Windows Vista. |
Server | Requires IIS 7 on Windows Vista. |
Product | IIS 7 |
Header | Httpserv.h |
Reference