Share via


IWMSCacheProxy::QueryCache

banner art

Previous Next

IWMSCacheProxy::QueryCache

The QueryCache method is called by the server to direct the cache plug-in to search the cache for specific content.

Syntax

  HRESULT QueryCache(
  
  BSTR
  
  bstrOriginUrl
  ,
  IWMSContext*  
  pUserContext
  ,
  
  IWMSCommandContext*
  
  pCommandContext
  ,
  
  IWMSContext*
  
  pPresentationContext
  ,
  
  long
  
  lQueryType
  ,
  
  IWMSCacheProxyCallback*
  
  pCallback
  ,
  
  VARIANT
  
  varContext
  
  );

Parameters

bstrOriginUrl

[in] BSTR containing the origin URL.

pUserContext

[in] Pointer to an IWMSContext interface containing the user context.

pCommandContext

[in] Pointer to an IWMSCommandContext interface containing the command context.

pPresentationContext

[in] Pointer to an IWMSContext interface containing the presentation context.

lQueryType

[in] Member of the WMS_CACHE_QUERY_TYPE_FLAGS enumeration type that indicates why the server called IWMSCacheProxy::QueryCache. This must be one of the following values.

Value Description
WMS_CACHE_QUERY_OPEN A client using a downstream proxy requested content.
WMS_CACHE_QUERY_GET_CONTENT_INFO A downstream proxy requested information about content cached on the remote computer.
WMS_CACHE_QUERY_CACHE_EVENT A cache event notice is being sent upstream. If WMS_CACHE_QUERY_LOCAL_EVENT is set, the cache event was generated by the local computer. Otherwise, it was sent by a downstream proxy server.
WMS_CACHE_QUERY_REVERSE_PROXY A downstream server is configured to be a reverse proxy server. If a cache proxy plug-in supports reverse proxy, it can use this flag to determine whether it must map client requests to an upstream server farm.
WMS_CACHE_QUERY_LOCAL_EVENT The local server is generating an event to send upstream.

pCallback

[in] Pointer to an IWMSCacheProxyCallback interface. The cache plug-in calls IWMSCacheProxyCallback::OnQueryCache to respond to a call to QueryCache.

varContext

[in] VARIANT containing a value defined by the server to identify which call to QueryCache the plug-in is responding to when it calls IWMSCacheProxyCallback::OnQueryCache. The plug-in must pass this value back unaltered.

Return Values

If the method succeeds, the plug-in must return S_OK. To report an error, the plug-in can return any HRESULT other than S_OK. If the plug-in uses the IWMSEventLog interface to log error information directly to the Windows Event Viewer, it is recommended that it return NS_E_PLUGIN_ERROR_REPORTED. Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog interface to send custom error information to the Windows Event Viewer, returning NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about retrieving plug-in error information, see Identifying Plug-in Errors.

Example Code

HRESULT STDMETHODCALLTYPE 
CCachePlugin::QueryCache( BSTR bstrOriginUrl,
                          IWMSCommandContext *pCommandContext,
                          IWMSContext *pPresentationContext,
                          long lBitFlags,
                          IWMSCacheProxyCallback *pCallback,
                          VARIANT varContext
                          )
{
    HRESULT hr = S_OK;
    IWMSContext *pContentInfo = NULL;
    WMS_CACHE_QUERY_RESPONSE OpenResponse;

    // You can implement a database to track cached content.
    pCacheEntry = m_CacheDatabase.Find( bstrOriginUrl );
    if( NULL == m_pCacheEntry )
    {
        // The content is not in the cache.
        OpenResponse = WMS_CACHE_QUERY_MISS; 
    }
    else
    {
        // The content is cached and you need to determine whether 
        // it has expired. Expiration is the length of time, from 
        // the moment at which content was last cached, that it can 
        // be made available to a client.
        // The UpdateContentTime() function and the 
        // NeedToCheckVersion() function are user-defined.
        pCacheEntry->UpdateContentTime();
        if( !pCacheEntry->NeedToCheckVersion() )
        {
            // If the content has not expired, signal a cache hit.
            OpenResponse = WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND;
            hr = S_OK;
            goto exit;
        }
        hr = pCacheEntry->GetContentInformation( &pContentInfo );
        hr = pCacheProxyCallback->CompareContentInformation(
                                            bstrOriginUrl,
                                            pContentInfo,
                                            pPresentationContext,
                                            this,
                                            (IWMSProxyContext*) this,
                                            this,
                                            varContext
                                            );

        return( S_OK );
    }

EXIT:
    if( NULL != pCacheEntry )
    {
        pCacheEntry->GetCacheUrl( & bstrOriginUrl );
    }

    // Call OnQueryCache and send a cache hit or 
    // miss to the server.
    hr = pCacheProxyCallback->OnQueryCache(
                               hr,
                               OpenResponse,
                               bstrOriginUrl,
                               m_pContentInfoContext,
                               (IUnknown *) m_pCachePluginContext,
                               varContext
                               );
    return( S_OK );
}

Requirements

Header: streamcache.h.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Previous Next