APGen Documentation Previous Topic: Page Fragment Caching Next Topic: ASPCache Best Practices Parent Topic: Introduction to ASPCache    Introduction to ASPCache
Using ASPCache in VB COM Components
See Also:

The ASPCache object can be used in VB applications, and in VB COM components.  This topic shows how to access an ASPCache object from a VB COM component that is instantiated in an ASP page.

To give the ASPCache object application scope, it must be instantiated in the global.asa file.  Application scope is necessary to keep cached data around between ASP page requests.

REM  *** global.asa ***

<OBJECT RUNAT=Server SCOPE=Application ID=Cache PROGID=ASPCache></OBJECT>

The ASP page instantiates your VB COM object:

<% @LANGUAGE="VBScript" %>
<% Option Explicit %>
<%

' Instantiate the VB COM object
Dim oMyVBPageObject
Set oMyVBPageObject = Server.CreateObject("MyLibrary.MyVBPageObject")

' Perform all page processing in the VB object
oMyVBPageObject.ProcessPage

%>

The VB COM Component

Within the VB COM component, the ObjectContext object is used to get a reference to the ASP Application object, and the Application object is used to get a reference to the ASPCache object.

Public Sub ProcessPage
   ...

'=============================================================
'   This code demonstrates how to access an ASPCache object
' within a VB COM component.
' Note that the following References must be set
' for the project:
'   ASPCache 1.1 Type Library
'   Microsoft Active Server Page Object Library
'   COM+ Services Type Library (or MTS Type Library on NT4)
'
' Also, the ASPCache object must be instantiated in
' global.asa, with name=Cache.
'=============================================================

Dim oCtx As ObjectContext
Set oCtx = GetObjectContext

' Get the Application object
Dim Application As ASPTypeLibrary.Application
Set Application = oCtx.Item("Application")

' Get the ASPCache object
Dim oCache As AspCacheLib.ASPCache
Set oCache = Application.StaticObjects("Cache")

' Now the ASPCache object can be used normally
   ...

Note that references to these type libraries should be added to the VB project: