Partager via


IWMSCacheProxy.QueryCache (Visual Basic .NET)

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

IWMSCacheProxy.QueryCache(  bstrOriginUrl As String,
  pUserContext As IWMSContext,
  pCommandContext As IWMSCommandContext,
  pPresentationContext As IWMSContext,
  lQueryType As Int32,
  pCallback As IWMSCacheProxyCallback,
  varContext As Object
)

Arguments

[in] String containing the origin URL.

[in] IWMSContextIWMSContext Object (Visual Basic .NET) containing the User Context.

[in] IWMSCommandContextIWMSCommandContext Object (Visual Basic .NET) containing the Command Context.

IWMSContext object containing the Presentation Context.

[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 the 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.

[in] IWMSCacheProxyCallbackIWMSCacheProxyCallback Object (Visual Basic .NET) containing the callback function. The cache plug-in calls IWMSCacheProxyCallback.OnQueryCache to respond to a call to QueryCache.

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

Return Value

This method does not return a value.

Example

Imports Microsoft.WindowsMediaServices.Interop
Imports System.Runtime.InteropServices

Public Sub QueryCache(ByVal OriginUrl As String, _
                      ByVal UserContext As IWMSContext, _
                      ByVal CommandContext As IWMSCommandContext, _
                      ByVal PresentationContext As IWMSContext, _
                      ByVal lQueryType As Integer, _
                      ByVal Callback As IWMSCacheProxyCallback, _
                      ByVal varContext As Object) _
  Implements IWMSCacheProxy.QueryCache

    Dim nFlag As Integer
    Dim nOpen As Integer
    Dim nGCI As Integer
    Dim nReverseProxy As Integer
    Dim Context As IWMSContext
    Dim Response As WMS_CACHE_QUERY_RESPONSE
    Dim ci As ContentInfo
    Dim bQueryCache As Boolean
    Dim bOnDemand As Boolean
    Dim now As Date
    Dim CacheUrl As String
    Dim nCacheEvent As Integer
    Dim nLocalEvent As Integer


    Try
        ' Intialize default values.
        bQueryCache = True
        bOnDemand = True

        ' Either a get content information (GCI) or an open call is made.
        If nOpen <> 0 Or nGCI <> 0 Then

            ' Retrieve a user-defined ContentInfo object. This
            ' object stores information about an item of
            ' cached content.
            GetContentInfo(OriginUrl, ci)
            ci.CacheProxyCallback = Callback
            ci.varContext = varContext

            ' Allocate a new content information context
            GetContentInfoContext(ci, Context)

            ' This is not a reverse proxy, and content has been cached.
            If ci.CacheUrl <> "" And nReverseProxy = 0 Then

                ' Convert the current time to UTC time. If the
                ' content has not expired, declare either a
                ' broadcast or on-demand cache hit.
                now = DateTime.Now.ToUniversalTime
                If (ci.ContentType And 1) <> 0 Then
                    Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_BROADCAST
                    bOnDemand = False
                Else
                    Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND
                    bOnDemand = True
                End If

            Else
                ' The content has expired.
                If nOpen <> 0 Then
                    bQueryCache = False
                End If
            End If

            If bQueryCache = True Then
                ' Retrieve the cache URL and call OnQueryCache.
                CacheUrl = ci.CacheUrl
                If bOnDemand = True Then
                    CacheUrl = String.Format("file://", ci.CacheUrl)
                End If
                Callback.OnQueryCache(0, Response, CacheUrl, Context, Nothing, varContext)
            Else
                ' The content has expired. Call CompareContentInformation
                ' (for open requests only). The CacheProxyServer object
                ' is your plug-in's implementation of the 
                ' IWMSCacheProxyServer object.
                CacheProxyServer.CompareContentInformation(OriginUrl, _
                                                           Context, _
                                                           PresentationContext, _
                                                           Me, _
                                                           Nothing, _
                                                           Me, _
                                                           ci)
            End If
        Else
            ' The request is not a GCI or an open call. 
            ' Determine whether it is an event.
            nCacheEvent = lQueryType And WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT
            nLocalEvent = lQueryType And WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_LOCAL_EVENT

            ' Declare a cache miss and ask the server to 
            ' forward the request.
            If nCacheEvent <> 0 Or nLocalEvent <> 0 Then
                Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS
                Callback.OnQueryCache(0, Response, OriginUrl, Nothing, Nothing, varContext)
            End If
        End If

    Catch
        Throw New COMException()
    End Try

End Sub

Requirements

Reference: Add a reference to Microsoft.WindowsMediaServices.

Namespace: Microsoft.WindowsMediaServices.Interop.

Assembly: Microsoft.WindowsMediaServices.dll.

Library: WMSServerTypeLib.dll.

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

See Also

Concepts

IWMSCacheProxy Object (Visual Basic .NET)