This VBScript example creates a new FPCURLSet object in the FPCURLSets collection of a Forefront TMG computer serving as a proxy, adds URLs to the URL set, and creates two new FPCCacheRule objects representing cache rules for caching content with a fixed range of Time to Live (TTL) values from all sites on the External network, except the sites in the new URL set. The script includes a single subroutine, called AddCacheRule.
This example is included as the AddCacheRule.vbs script in the Samples\Admin folder of the Forefront TMG Software Development Kit (SDK).
The following procedure lists the steps used to add two cache rules in the code example that follows.
To add cache rules
The following code can be saved to a .vbs file and run from a command prompt on a computer running Forefront TMG with the Microsoft Firewall service installed.
Sub AddCacheRule() ' Define enumeration values. Const fpcInclude = 0 Const fpcExclude = 1 Const fpcTimeInHours = 3 ' Create the root object. Dim root ' The FPCLib.FPC root object Set root = CreateObject("FPC.Root") 'Declare the other objects needed. Dim isaArray ' An FPCArray object Dim rules ' An FPCCacheRules collection Dim urlsets ' An FPCURLSets collection Dim urlset ' An FPCURLSet object Dim newRule1 ' An FPCCacheRule object Dim newRule2 ' An FPCCacheRule object ' Get references to the array object, the cache ' rules collection, and the URL sets collection. Set isaArray = root.GetContainingArray() Set rules = isaArray.Cache.CacheConfiguration.CacheRules Set urlsets = isaArray.RuleElements.URLSets ' If a URL set named "Not for Caching" already exists, remove it. On Error Resume Next Set urlset = urlsets.Item("Not for Caching") If Err.Number = 0 Then WScript.Echo "The Not for Caching URL set exists. Removing it ..." urlsets.Remove "Not for Caching" urlsets.Save End If WScript.Echo "Creating a new URL set for exclusion from caching ..." Set urlset = urlsets.Add("Not for Caching") urlset.Add "http://www.northwindtraders.com" urlset.Add "http://www.northwindtraders.com/*" urlsets.Save ' If a cache rule named "Shorter TTL Cache Rule" already exists, remove it. On Error Resume Next Set newRule1 = rules.Item("Shorter TTL Cache Rule") If Err.Number = 0 Then WScript.Echo "Shorter TTL Cache Rule exists. Removing it ..." rules.Remove "Shorter TTL Cache Rule" rules.Save End If ' If a cache rule named "Excluded Cache Rule" already exists, remove it. On Error Resume Next Set newRule2 = rules.Item("Excluded Cache Rule") If Err.Number = 0 Then WScript.Echo "Excluded Cache Rule rule exists. Removing it ..." rules.Remove "Excluded Cache Rule" rules.Save End If WScript.Echo "Creating new cache rules ..." Set newRule2 = rules.Add("Excluded Cache Rule") Set newRule1 = rules.Add("Shorter TTL Cache Rule") ' Set the descriptions of the new cache rules. newRule1.Description = "This rule caches content with a shorter TTL " & _ "in response to requests sent to sites on the " & _ "External network except for specific URLs." newRule2.Description = "This rule prohibits caching of content " & _ "from specific URLs." ' Add the External network to the first rule. newRule1.DestinationSelectionIPs.Networks.Add "External", fpcInclude ' Add the new URL set as an exception to the objects referenced by ' the URLSets property of the first cache rule and as an included ' object in the second cache rule. newRule1.UrlSets.Add "Not for Caching", fpcExclude newRule2.UrlSets.Add "Not for Caching", fpcInclude ' Set shorter TTLs for all requests to which the first rule applies. newRule1.HTTPConfiguration.ApplyBoundsToObjectsWithExpiration = True newRule1.HTTPConfiguration.MinInterval = minTTL newRule1.HTTPConfiguration.MaxIntervalUnits = fpcTimeInHours newRule1.HTTPConfiguration.MaxIntervalValue = maxTTL ' Set no caching for all requests to which the second rule applies. newRule2.NeverCacheResponse = True ' Save the changes to the new cache rules. rules.Save WScript.Echo "Done!" End Sub AddCacheRule
Send comments about this topic to Microsoft
Build date: 11/30/2009
© 2008 Microsoft Corporation. All rights reserved.