<%
' Copyright 2000 Phone.com, Inc.  All rights reserved.
'
'   Subject to the terms and conditions of the SDK License Agreement, 
'   Phone.com, Inc. hereby grants you the right to use the UP.SDK 
'   software and its related documentation.
'
'   The Phone.com name and logo and the family of terms carrying the "UP."
'   prefix are trademarks of Phone.com, Inc. All other brands and product 
'   names may be trademarks of the respective companies with which they 
'   are associated.
' 
' 
' cacheop.asp
'
'   An ASP example modeled upon the Perl cacheop.cgi example.
'
' Cache management example
' 
'   - This example demonstrates how to use cache operations
'     and cache-control meta elements to override the default 
'     caching behavior of the UP.Browser.
'
' Key concepts illustrated include:
'
'     - Adding a cache operation to a digest. In this app, we use
'       the 'invalidate URL' cache operation to invalidate a single
'       deck. Applications can also use the 'invalidate service' 
'       cache operation to invalidate several decks in the cache 
'       at once.
'
'     - Using a Cache-control meta element to set a deck's TTL
'       (time-to-live) in the cache to 0 (i.e. invalidate the deck
'       immediately) via the "no-cache" option.  
'
'     - Using a Cache-control meta element to force a deck's
'       TTL to be revalidated, even if the user navigates to it in
'       the backward direction via the "must-revalidate" option.  
'
' Declarations 
' 
Dim myDigest, deckh, deck1, deck2, deck3, digestString, nl

' Constants
' 
' A newline (linefeed) is appended to each line of WML to
' aid legibility of source dumped to the Sim Info Window.
' 
nl = Chr(10)

' The WML Decks
'
' An home deck, allows user selection among two demonstrations
'
deckh =         "<wml>" & nl
deckh = deckh & "  <card>" & nl
deckh = deckh & "    <p>" & nl
deckh = deckh & "      Cache Management" & nl
deckh = deckh & "      <select>" & nl
deckh = deckh & "        <option onpick=""?DEMO=CACHEOP"">"
deckh = deckh &            "Cache operation</option>" & nl
deckh = deckh & "        <option onpick=""?DEMO=CONTROL"">"
deckh = deckh &            "Cache control</option>" & nl
deckh = deckh & "      </select>" & nl
deckh = deckh & "    </p>" & nl
deckh = deckh & "  </card>" & nl
deckh = deckh & "</wml>" & nl

' First cache operation demo deck. 
'
deck1 =         "<wml>" & nl
deck1 = deck1 & "  <card>" & nl
deck1 = deck1 & "    <do type=""accept"" label=""Yes"">" & nl
deck1 = deck1 & "      <go href=""?DEMO=CACHEOP&amp;NEXT=YES""/>" & nl
deck1 = deck1 & "    </do>" & nl
deck1 = deck1 & "    <p>" & nl
deck1 = deck1 & "      Invalidate this deck with a cache operation?" & nl
deck1 = deck1 & "      <br/>" & Now() & nl
deck1 = deck1 & "    </p>" & nl
deck1 = deck1 & "  </card>" & nl
deck1 = deck1 & "</wml>" & nl

' Second cache operation demo deck.
'
deck2 =         "<wml>" & nl
deck2 = deck2 & "  <head>" & nl
deck2 = deck2 & "    <meta forua=""true"" http-equiv=""Cache-Control"" "
deck2 = deck2 &        "content=""no-cache""/>" & nl
deck2 = deck2 & "  </head>" & nl
deck2 = deck2 & "  <card>" & nl
deck2 = deck2 & "    <p>" & nl
deck2 = deck2 & "      Previous deck was invalidated and "
deck2 = deck2 &        "will be reloaded from server." & nl
deck2 = deck2 & "    </p>" & nl
deck2 = deck2 & "  </card>" & nl
deck2 = deck2 & "</wml>" & nl

' First cache control demo deck.
'
deck3 =         "<wml>" & nl
deck3 = deck3 & "  <head>" & nl
deck3 = deck3 & "    <meta forua=""true"" http-equiv=""Cache-Control"" "
deck3 = deck3 &        "content=""no-cache""/>" & nl
deck3 = deck3 & "    <meta forua=""true"" http-equiv=""Cache-Control"" "
deck3 = deck3 &        "content=""must-revalidate""/>" & nl
deck3 = deck3 & "  </head>" & nl
deck3 = deck3 & "  <card>" & nl
deck3 = deck3 & "    <do type=""accept"" label=""Yes"">" & nl
deck3 = deck3 & "      <go href=""?DEMO=CONTROL&amp;NEXT=YES""/>" & nl
deck3 = deck3 & "    </do>" & nl
deck3 = deck3 & "    <p>" & nl
deck3 = deck3 & "      This deck has cache control meta tags." & nl
deck3 = deck3 & "      Force the browser to revalidate?" & nl
deck3 = deck3 & "      <br/>" & Now() & nl
deck3 = deck3 & "    </p>" & nl
deck3 = deck3 & "  </card>" & nl
deck3 = deck3 & "</wml>" & nl

' Second cache control demo deck.
'
deck4 =         "<wml>" & nl
deck4 = deck4 & "  <head>" & nl
deck4 = deck4 & "    <meta forua=""true"" http-equiv=""Cache-Control"" "
deck4 = deck4 &        "content=""no-cache""/>" & nl
deck4 = deck4 & "  </head>" & nl
deck4 = deck4 & "  <card>" & nl
deck4 = deck4 & "    <p>" & nl
deck4 = deck4 & "      Previous deck will be revalidated and "
deck4 = deck4 &        "reloaded from server." & nl
deck4 = deck4 & "    </p>" & nl
deck4 = deck4 & "  </card>" & nl
deck4 = deck4 & "</wml>" & nl

' Create a new COM Digest object for each deck.
'
set myDigest  = Server.CreateObject("PDCDigestUtils.CPDCDigest")

' Use the ASP built-in Request object to retrieve values passed in HTTP
'
If 0 = Request.QueryString.Count Then
'   Found an empty query string.
'   Add the home deck to the digest with an empty relative URL
'
    myDigest.DigestAddDeck "", deckh
Else
'   Found a non-empty query string in the request; 
'   assume it contains "DEMO" and match its argument
'
    If "CACHEOP" = Request.QueryString("DEMO")(1) Then
'
'       Demonstrate cache operations
'
        If 0 = InStr(Request.QueryString, "NEXT") Then
'
'       Return the initial cache-op demo deck by adding 
'       it to a digest with an empty relative URL.
'
            myDigest.DigestAddDeck "", deck1
        Else
'
'           Return a deck which contains a "no-cache" meta element, and
'           invalidate the previous (cache-op demo) deck in the cache.  
'           Use a relative URL to identify the deck to be invalidated.
'
            myDigest.DigestAddDeck "", deck2
            myDigest.DigestAddCacheOp "InvalidateURL", "?DEMO=CACHEOP"
        End If

    ElseIf "CONTROL" = Request.QueryString("DEMO")(1) Then
'
'       Demonstrate cache control 
'
        If 0 = InStr(Request.QueryString, "NEXT") Then
'
'           Return the initial cache-control demo deck.
'
            myDigest.DigestAddDeck "", deck3
        Else
'
'           Return the deck which uses a default "OK" operation 
'           to go back to the demo deck.
'
            myDigest.DigestAddDeck "", deck4
        End If
    End If
End If

' Suppress content type output within the digest to prevent a 
' server from encapsulating WML content within a second boundary.
'
myDigest.DigestSuppressContentType 1

' Serialize the digest into a single output buffer, digestString.
'
digestString    = myDigest.DigestSerialize(0)

' Specify a deck of type WML to the digest object.
'
myDigest.DeckType         = 1

' Specify content type through the server response,
' rather than within the digest.
'
Response.ContentType    = myDigest.DigestGetContentType

' Write the response buffer to the client.
'
Response.BinaryWrite(digestString)
%>
