IWMSCacheProxyCallback::OnQueryCache

banner art

Previous Next

IWMSCacheProxyCallback::OnQueryCache

The OnQueryCache method is called by the cache plug-in to respond when the server calls IWMSCacheProxy::QueryCache.

Syntax

  HRESULT OnQueryCache(
  
  HRESULT
  
  hr
  ,
  
  WMS_CACHE_QUERY_RESPONSE
  
  Response
  ,
  
  BSTR
  
  bstrCacheUrl
  ,
  IWMSContext*  
  pContentInfo
  ,
     IUnknown* pCachePluginContext,VARIANTvarContext);

Parameters

hr

[in] HRESULT indicating whether the call to IWMSCacheProxy::QueryCache was successful.

Response

[in] Member of the WMS_CACHE_QUERY_RESPONSE enumeration type indicating the response of the cache plug-in. This must be one of the following values.

Value Description
WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND The requested content is in the cache and is current. Therefore, it may be streamed from the cache or proxied from an upstream server. Each client request requires a separate connection.
WMS_CACHE_QUERY_HIT_PLAY_BROADCAST The requested content is in the cache and is current. Therefore, it may be streamed from the cache or proxied from an upstream server. A single stream can be split to multiple downstream clients.
WMS_CACHE_QUERY_HIT_PROCESS_REQUEST The requested content is in the cache. The server must process the request and send information about the result to the downstream client. This response is only valid if the server has called QueryCache and specified either WMS_CACHE_QUERY_GET_CONTENT_INFO or WMS_CACHE_QUERY_CACHE_EVENT.
WMS_CACHE_QUERY_MISS The requested content is not in the cache or is not current.

bstrCacheUrl

[in] BSTR containing the cache URL.

pContentInfo

[in] Pointer to an IWMSContext interface containing a content description context.

pCachePluginContext

[in] Pointer to an IUnknown interface containing information defined by the cache plug-in. The server does not use this information. It passes the pointer back to the plug-in when it calls IWMSCacheProxy::QueryCacheMissPolicy.

varContext

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

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
E_INVALIDARG 0x80070057 The pContentInfo parameter is NULL and the plug-in returned WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND in the Response parameter.
E_INVALIDARG 0x80070057 The VarContext parameter does not contain a pointer to an IUnknown interface.
E_INVALIDARG 0x80070057 The bstrCacheUrl parameter is NULL.
E_INVALIDARG 0x80070057 The plug-in returned WMS_CACHE_QUERY_HIT_PROCESS_REQUEST in the Response parameter when the server called QueryCache and specified WMS_CACHE_QUERY_GET_CONTENT_INFO or WMS_CACHE_QUERY_CACHE_EVENT.
E_OUTOFMEMORY 0x80070057 The bstrCacheUrl parameter is NULL.

Example Code

HRESULT STDMETHODCALLTYPE 
CCachePlugin::QueryCache( BSTR bstrOriginUrl,
                          IWMSCommandContext *pCommandContext,
                          IWMSContext *pPresentationContext,
                          long lBitFlags,
                          IWMSCacheProxyCallback *pCallback,
                          VARIANT varContext
                          )
{
    HRESULT hr = S_OK;
    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;
        }

        // The content has expired. Start the protocol rollover
        // process by initializing an index into an array of
        // protocols supported by this plug-in. For example, the
        // g_ProxyProtocols array can contain a list of the
        // protocols supported by the plug-in.
        // LPWSTR g_ProxyProtocols[]={L"HTTP", L"RTSP", NULL}.
        // In the following example, the protocol index is a
        // global variable, but it can also be passed as part of
        // the context identified by the fourth parameter of the
        // OnCompareContentInformation() method.

        g_ProtocolIndex = -1;
        OnCompareContentInformation( NS_E_CONNECTION_FAILURE, 
                               WMS_CACHE_VERSION_FAIL_TO_CHECK_VERSION, 
                               NULL, 
                               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