IHttpResponse::D isableKernelCache 方法
停用此回應的核心快取。
語法
virtual VOID DisableKernelCache(
ULONG reason = 9
) = 0;
參數
reason
停用核心快取的選擇性原因。
傳回值
VOID
.
備註
方法 DisableKernelCache
會停用目前回應的核心快取。
您可以選擇性地傳遞 reason
參數,其中包含列舉中 IISCacheEvents::HTTPSYS_CACHEABLE::enumReason
定義的值,以指出您停用快取的原因。
注意
如果您未將參數傳遞 reason
至 DisableKernelCache
方法,則會使用預設值 9 (HANDLER_HTTPSYS_UNFRIENDLY
) 。
範例
下列程式碼範例示範如何使用 DisableKernelCache
方法來停用目前要求的核心快取。
注意
如果您想要傳回目前的快取狀態,請結合此範例模組與針對 GetKernelCacheEnabled 方法列出的範例模組。
#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
);
}
您的模組必須匯出 RegisterModule 函式 。 您可以為專案建立模組定義 (.def) 檔案,或使用 參數編譯模組 /EXPORT:RegisterModule
來匯出此函式。 如需詳細資訊,請參閱逐步解說 :使用機器碼建立Request-Level HTTP 模組。
您可以選擇性地使用呼叫慣例編譯器代碼, __stdcall (/Gz)
而不是明確宣告每個函式的呼叫慣例。
規格需求
類型 | 描述 |
---|---|
Client | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10上的 IIS 10.0 |
伺服器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016上的 IIS 10.0 |
產品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 - IIS Express 7.5、IIS Express 8.0、IIS Express 10.0 |
標頭 | Httpserv.h |
另請參閱
IHttpResponse 介面
IHttpResponse::GetCachePolicy 方法
IHttpResponse::GetKernelCacheEnabled 方法
IHttpServer::FlushKernelCache 方法