Prestuffing a Cache

Prestuffing a cache (caching content before it is requested) allows a cache proxy server to start streaming content immediately from cache rather than first downloading it or proxying it from an upstream server. This minimizes latency and required bandwidth. Content caching requires a cache proxy plug-in. Windows Media Services does not include a cache proxy plug-in, but you can make your own. For more information, see Creating Cache Proxy Plug-ins. To enable cache prestuffing, use the PreStuff method on the IWMSCacheProxyPlugin interface. This is illustrated by the following example.

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

' Declare variables.
Dim Server As WMSServer
Dim CacheProxyPlugin As IWMSCacheProxyPlugin

Try

    ' Create the WMSServer object.
    Server = New WMSServer()

    ' Retrieve the first cache proxy plug-in.
    CacheProxyPlugin = Server.CacheProxy(0)

    ' Prestuff the cache from a specified file and server.
    CacheProxyPlugin.PreStuff("http://server_name", "c:\wmpub\wmroot\ad1.wmv", 1, 0, 0)

Catch errCom As COMException
    ' TODO: Handle COM exceptions.
Catch err As Exception
    ' TODO: Exception handler goes here.
Finally
    ' TODO: Clean-up code goes here.
End Try


using Microsoft.WindowsMediaServices.Interop;
using System.Runtime.InteropServices;

// Declare variables.
WMSServer Server;
IWMSCacheProxyPlugin CacheProxyPlugin;

try
{

    // Create the WMSServer object.
       Server = new WMSServerClass();

    // Retrieve the first cache proxy plug-in.
    CacheProxyPlugin = (IWMSCacheProxyPlugin)Server.CacheProxy[0];

    // Prestuff the cache from a specified file and server.
    CacheProxyPlugin.PreStuff("http://server_name", "c:\\wmpub\\wmroot\\ad1.wmv", -1, 0, 0);
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception exc)
{
    MessageBox.Show(exc.ToString(), "Example 18");
    // TODO: Exception handler goes here.
}
finally
{
    // TODO: Clean-up code goes here.
}


#include <windows.h>
#include <atlbase.h>    // Includes CComBSTR and CComVariant.
#include "wmsserver.h"

// Declare variables and interfaces.
IWMSServer              *pServer;
IWMSPlugins             *pPlugins;
IWMSPlugin              *pPlugin;
IWMSCacheProxyPlugin    *pCacheProxyPlugin;

HRESULT         hr;
CComVariant     varIndex;
CComBSTR        bstrOriginURL;
CComBSTR        bstrSourcePath;
long            lCount;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
if (FAILED(hr)) goto EXIT;

// Retrieve a list of cache proxy plug-ins.
hr = pServer->get_CacheProxy(&pPlugins);
if (FAILED(hr)) goto EXIT;

// Retrieve the total count of cache proxy plug-ins.
hr = pPlugins->get_Count(&lCount);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the first cache proxy plug-in.
varIndex = 0;
hr = pPlugins->get_Item(varIndex, &pPlugin);
if (FAILED(hr)) goto EXIT;

// Query a pointer to the IWMSCacheProxyPlugin interface.
hr = pPlugin->QueryInterface(IID_IWMSCacheProxyPlugin, 
                            (void **)&pCacheProxyPlugin);
if (FAILED(hr)) goto EXIT;

// Prestuff the cache from a specified file and server.
bstrSourcePath = "c:\\wmpub\\wmroot\\ad1.wmv"
bstrOriginURL = "http://server_name";
hr = pCacheProxyPlugin->PreStuff(bstrOriginURL,
                                 bstrSourcePath,
                                 -1, 0, 0);
if (FAILED(hr)) goto EXIT;

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.


Show: