Page.NavigationCacheMode Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether this page is cached and whether it is cached indefinitely.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)

Syntax

'Declaration
Public Property NavigationCacheMode As NavigationCacheMode
public NavigationCacheMode NavigationCacheMode { get; set; }
<sdk:Page NavigationCacheMode="navigationCacheModeValue"/>

XAML Values

  • navigationCacheModeValue
    A named constant of the NavigationCacheMode enumeration, such as Required.

Property Value

Type: System.Windows.Navigation.NavigationCacheMode
The value that specifies the caching behavior for this page.

Remarks

You use the NavigationCacheMode property to specify whether a new instance of the page is created for each visit to the page or if a previously constructed instance of the page that has been saved in the cache is used for each visit.

The default value for the NavigationCacheMode property is Disabled. Set the NavigationCacheMode property to Enabled or Required when a new instance of the page is not essential for each visit. By using a cached instance of the page, you can improve the performance of your application and reduce the load on your server.

Setting NavigationCacheMode to Required means that the page is cached regardless of the number of cached pages specified in the CacheSize property. Pages marked as Required do not count against the CacheSize total. Setting NavigationCacheMode to Enabled means the page is cached, but it is eligible for disposal if the number of cached pages exceeds the value of CacheSize.

Set the NavigationCacheMode property to Disabled if a new instance must be created for each visit. For example, you should not cache a page that displays information that is unique to each customer.

The OnNavigatedTo method is called for each request, even when the page is retrieved from the cache. You should include in this method code that must be executed for each request rather than placing that code in the Page constructor.

Examples

The following example shows a Silverlight page that retrieves and displays data from a data source. The data that is retrieved is the performance schedule for an arts organization for the current month. The page is not likely to change often and the data retrieval is potentially time-consuming, so the NavigationCacheMode property is set to Enabled. The implementation of the data retrieval and display is not shown in this example.

<!-- NOTE: 
  By convention, the sdk prefix indicates a URI-based XAML namespace declaration 
  for Silverlight SDK client libraries. This namespace declaration is valid for 
  Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace 
  declarations for each CLR assembly and namespace combination outside the scope 
  of the default Silverlight XAML namespace. For more information, see the help 
  topic "Prefixes and Mappings for Silverlight Libraries". 
-->
<sdk:Page 
    x:Class="NavExample.Views.PerformanceSchedule" 
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sdk="https://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    Title="Current Month's Performance Schedule" 
    NavigationCacheMode="Enabled">

    <!-- Retrieve and display all performances for this month. -->
    <Grid x:Name="LayoutRoot">

    </Grid>
</sdk:Page>

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.