Visual Basic (Declaration) | |
---|---|
Public Shared Property DefaultCachePolicy As RequestCachePolicy |
C# | |
---|---|
public static RequestCachePolicy DefaultCachePolicy {get; set;} |
Setting the ArcGISWebClient.DefaultCachePolicy Property affects the caching policy of web traffic for all ArcGIS Runtime SDK for WPF API requests. This is in contrast to the Microsoft caching policy on the System.Net.WebRequest object, which requires modifying the Machine.Config file or setting the System.Net.HttpWebRequest.DefaultCachePolicy Property.
The ArcGISWebClient.DefaultCachePolicy Property is a Shared/static Property, this means that you do not use the 'new' keyword to instantiate an ArcGISWebClient object in order to use this Property.
How to use:
Change the options for the various System.Net.Cache.RequestCacheLevel Enumerations and then click the button. View the Headers of the web traffic in an internet monitoring application (like Fiddler) to see the various Cached policys being used.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | Copy Code |
---|---|
<Grid> <!-- Add a Map Control --> <esri:Map WrapAround="True" x:Name="MyMap" Margin="360,94,10,10"> <!-- Add an ArcGISTiledMapServiceLayer.--> <esri:ArcGISTiledMapServiceLayer ID="MyLayer" Url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer" /> </esri:Map> <!-- Add a ComboBox and a Button to the application. --> <ComboBox x:Name="RequestPolicyLevel" SelectionChanged="RequestPolicyLevel_SelectionChanged_1" Margin="14,156,446,374"/> <Button Content="Query" Click="Button_Click_1" Margin="13,117,447,421" /> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="94" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="625" TextWrapping="Wrap" Text="Change the options for the various System.Net.Cache.RequestCacheLevel Enumerations and then click the button. View the Headers of the web traffic in an internet monitoring application (like Fiddler) to see the various Cached policys being used." Margin="0,10,-108,0" /> </Grid> |
C# | Copy Code |
---|---|
public MainWindow() { InitializeComponent(); // Add the different System.Net.Cache.RequestCacheLevel to the ComboBox. RequestPolicyLevel.ItemsSource = new System.Net.Cache.RequestCacheLevel[] { System.Net.Cache.RequestCacheLevel.BypassCache, System.Net.Cache.RequestCacheLevel.CacheIfAvailable, System.Net.Cache.RequestCacheLevel.CacheOnly, System.Net.Cache.RequestCacheLevel.Default, System.Net.Cache.RequestCacheLevel.NoCacheNoStore, System.Net.Cache.RequestCacheLevel.Reload, System.Net.Cache.RequestCacheLevel.Revalidate }; // Set the default item to appear in the ComboBox when the application loads. RequestPolicyLevel.SelectedItem = System.Net.Cache.RequestCacheLevel.Default; } private void RequestPolicyLevel_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { // Get the System.Net.Cache.RequestCacheLevel from the selected ComboxBox selection. System.Net.Cache.RequestCacheLevel myRequestCacheLevel = (System.Net.Cache.RequestCacheLevel)((sender as ComboBox).SelectedItem); // Set the Shared/static ArcGISWebClient.DefaultCachePolicy Property. This will affect all ArcGIS Runtime SDK for WPF API calls. ESRI.ArcGIS.Client.ArcGISWebClient.DefaultCachePolicy = new System.Net.Cache.RequestCachePolicy(myRequestCacheLevel); } private void Button_Click_1(object sender, RoutedEventArgs e) { // Create a new QueryTask. ESRI.ArcGIS.Client.Tasks.QueryTask myQueryTask = null; myQueryTask = new ESRI.ArcGIS.Client.Tasks.QueryTask("http://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer/0"); // Execute the QueryTask. View the results of the web traffic in an applicaiton like Fiddler. myQueryTask.ExecuteAsync(new ESRI.ArcGIS.Client.Tasks.Query() { Where = "1=1" }); } |
VB.NET | Copy Code |
---|---|
Public Sub New() InitializeComponent() ' Add the different System.Net.Cache.RequestCacheLevel to the ComboBox. RequestPolicyLevel.ItemsSource = New System.Net.Cache.RequestCacheLevel() {System.Net.Cache.RequestCacheLevel.BypassCache, System.Net.Cache.RequestCacheLevel.CacheIfAvailable, System.Net.Cache.RequestCacheLevel.CacheOnly, System.Net.Cache.RequestCacheLevel.Default, System.Net.Cache.RequestCacheLevel.NoCacheNoStore, System.Net.Cache.RequestCacheLevel.Reload, System.Net.Cache.RequestCacheLevel.Revalidate} ' Set the default item to appear in the ComboBox when the application loads. RequestPolicyLevel.SelectedItem = System.Net.Cache.RequestCacheLevel.Default End Sub Private Sub RequestPolicyLevel_SelectionChanged_1(ByVal sender As Object, ByVal e As SelectionChangedEventArgs) ' Get the System.Net.Cache.RequestCacheLevel from the selected ComboxBox selection. Dim myRequestCacheLevel As System.Net.Cache.RequestCacheLevel = CType((TryCast(sender, ComboBox)).SelectedItem, System.Net.Cache.RequestCacheLevel) ' Set the Shared/static ArcGISWebClient.DefaultCachePolicy Property. This will affect all ArcGIS Runtime SDK for WPF API calls. ESRI.ArcGIS.Client.ArcGISWebClient.DefaultCachePolicy = New System.Net.Cache.RequestCachePolicy(myRequestCacheLevel) End Sub Private Sub Button_Click_1(ByVal sender As Object, ByVal e As RoutedEventArgs) ' Create a new QueryTask. Dim myQueryTask As ESRI.ArcGIS.Client.Tasks.QueryTask myQueryTask = New ESRI.ArcGIS.Client.Tasks.QueryTask("http://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer/0") ' Execute the QueryTask. View the results of the web traffic in an applicaiton like Fiddler. myQueryTask.ExecuteAsync(New ESRI.ArcGIS.Client.Tasks.Query() With {.Where = "1=1"}) End Sub |
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8