Partager via


CGlobalModule::OnGlobalCacheOperation, méthode

Représente la méthode qui gère un GlobalCacheOperation événement, qui se produit quand IIS effectue une opération liée au cache.

Syntaxe

virtual GLOBAL_NOTIFICATION_STATUS OnGlobalCacheOperation(  
   IN ICacheProvider* pProvider  
);  

Paramètres

pProvider
[IN] Pointeur vers une interface ICacheProvider .

Valeur renvoyée

Valeur GLOBAL_NOTIFICATION_STATUS .

Remarques

Lorsqu’un module global s’est inscrit pour la notification d’événement GL_CACHE_OPERATION , IIS appelle la méthode du OnGlobalCacheOperation module quand IIS effectue une opération liée au cache.

Notes

Les modules globaux peuvent s’inscrire à la GlobalCacheOperation notification d’événement en s’inscrivant à GL_CACHE_OPERATION dans la fonction RegisterModule du module.

Exemple

L’exemple de code suivant montre comment créer un module HTTP de niveau global qui s’inscrit pour la GL_CACHE_OPERATION notification. Lorsqu’une opération liée au cache se produit, IIS appelle la méthode de l’exemple de OnGlobalCacheOperation module. Cette méthode écrit une entrée dans le journal des applications du observateur d'événements Windows, puis quitte.

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

// Create the module's global class.
class MyGlobalModule : public CGlobalModule
{
public:

    // Process a GL_CACHE_OPERATION notification.
    GLOBAL_NOTIFICATION_STATUS
    OnGlobalCacheOperation(
        IN ICacheProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        WriteEventViewerLog("OnGlobalCacheOperation");
        return GL_NOTIFICATION_CONTINUE;
    }

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

    MyGlobalModule()
    {
        // Open a handle to the Event Viewer.
        m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
    }

    ~MyGlobalModule()
    {
        // Test whether the handle for the Event Viewer is open.
        if (NULL != m_hEventLog)
        {
            // Close the handle to the Event Viewer.
            DeregisterEventSource( m_hEventLog );
            m_hEventLog = NULL;
        }
    }

private:

    // Create a handle for the event viewer.
    HANDLE m_hEventLog;

    // Define a method that writes to the Event Viewer.
    BOOL WriteEventViewerLog(LPCSTR szNotification)
    {
        // Test whether the handle for the Event Viewer is open.
        if (NULL != m_hEventLog)
        {
            // Write any strings to the Event Viewer and return.
            return ReportEvent(
                m_hEventLog,
                EVENTLOG_INFORMATION_TYPE, 0, 0,
                NULL, 1, 0, &szNotification, NULL );
        }
        return FALSE;
    }
};

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

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

Votre module doit exporter la fonction RegisterModule . Vous pouvez exporter cette fonction en créant un fichier de définition de module (.def) pour votre projet, ou vous pouvez compiler le module à l’aide du /EXPORT:RegisterModule commutateur. Pour plus d’informations, consultez Procédure pas à pas : création d’un module HTTP Global-Level à l’aide de code natif.

Vous pouvez éventuellement compiler le code à l’aide de la __stdcall (/Gz) convention d’appel au lieu de déclarer explicitement la convention d’appel pour chaque fonction.

Spécifications

Type Description
Client - IIS 7.0 sur Windows Vista
- IIS 7.5 sur Windows 7
- IIS 8.0 sur Windows 8
- IIS 10.0 sur Windows 10
Serveur - IIS 7.0 sur Windows Server 2008
- IIS 7.5 sur Windows Server 2008 R2
- IIS 8.0 sur Windows Server 2012
- IIS 8.5 sur Windows Server 2012 R2
- IIS 10.0 sur Windows Server 2016
Produit - 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
En-tête Httpserv.h

Voir aussi

CGlobalModule, classe
CGlobalModule::OnGlobalCacheCleanup, méthode