IHttpServer::DoCacheOperation Method


Performs a specific cache operation.


virtual HRESULT DoCacheOperation(  
   IN CACHE_OPERATION cacheOperation,  
   IN IHttpCacheKey* pCacheKey,  
   OUT IHttpCacheSpecificData** ppCacheSpecificData,  
   IN IHttpTraceContext* pHttpTraceContext = NULL  
) = 0;  


[IN] A CACHE_OPERATION enumeration value.

[IN] A pointer to an IHttpCacheKey interface.

[OUT] A pointer to the address of an IHttpCacheSpecificData interface.

[IN] A pointer to an IHttpTraceContext interface. (Optional.)

Return Value

An HRESULT. Possible values include, but are not limited to, those in the following table.

Value Description
S_OK Indicates that the operation was successful.


The DoCacheOperation method is used in HTTP modules to perform the cache operation that is specified by the cacheOperation parameter. For example, the CACHE_OPERATION_ADD and CACHE_OPERATION_DELETE enumeration values store or remove objects, respectively, from the cache. When your module calls the DoCacheOperation method, it must pass an IHttpCacheKey interface in the pCacheKey parameter, and IIS will return an IHttpCacheSpecificData interface in the ppCacheSpecificData parameter. You can optionally specify an IHttpTraceContext interface in the pHttpTraceContext parameter to identify the request that triggered the call. (This is necessary only for tracing purposes.)


Implementers should not call DoCacheOperation inside of IHttpApplicationResolveModulesProvider::RegisterModule Method because it is too early in the request pipeline.


The following code example demonstrates how to use the DoCacheOperation method to create an HTTP module that tests for a CACHE_OPERATION_RETRIEVE operation and triggers a CACHE_OPERATION_ENUM operation.

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>

IHttpServer * g_pGlobalInfo;

// Create the module's global class.
class MyGlobalModule : public CGlobalModule
        IN ICacheProvider * pProvider
        if (CACHE_OPERATION_RETRIEVE == pProvider->GetCacheOperation())
            // Retrieve an IHttpCacheKey interface.
            IHttpCacheKey * pCacheKey = pProvider->GetCacheKey();
            // Test for an error.
            if (NULL == pCacheKey) return GL_NOTIFICATION_CONTINUE;
            // Initialize an IHttpCacheSpecificData interface pointer.
            IHttpCacheSpecificData * pCacheSpecificData = NULL;
            // Peform a cache enumeration operation.
            HRESULT hr = g_pGlobalInfo->DoCacheOperation(
            // Test for an error.
            if (FAILED(hr)) return GL_NOTIFICATION_HANDLED;

        // Return processing to the pipeline.

    VOID Terminate()
        // Remove the class from memory.
        delete this;


// Create the module's exported registration function.
    DWORD dwServerVersion,
    IHttpModuleRegistrationInfo * pModuleInfo,
    IHttpServer * pGlobalInfo
    UNREFERENCED_PARAMETER( dwServerVersion );

    g_pGlobalInfo = pGlobalInfo;

    // Create an instance of the global module class.
    MyGlobalModule * pGlobalModule = new MyGlobalModule;
    // Test for an error.
    if (NULL == pGlobalModule)
    // Set the global notifications and exit.
    return pModuleInfo->SetGlobalNotifications(
        pGlobalModule, GL_CACHE_OPERATION );

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.

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 - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - IIS 7.0 on Windows Server 2008
- 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 Technical Preview
Product - 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
Header Httpserv.h

See Also

IHttpServer Interface
IHttpCacheKey Interface
IHttpCacheSpecificData Interface
IHttpTraceContext Interface