Chart.SaveToCache Method

Saves a chart in the system cache.

Namespace:  System.Web.Helpers
Assembly:  System.Web.Helpers (in System.Web.Helpers.dll)

public string SaveToCache(
	string key,
	int minutesToCache,
	bool slidingExpiration


Type: System.String
The ID of the chart in the cache.
Type: System.Int32
The number of minutes to keep the chart image in the cache. The default is 20.
Type: System.Boolean
true to indicate that the chart cache item's expiration is reset each time the item is accessed, or false to indicate that the expiration is based on an absolute interval since the time that the item was added to the cache. The default is true.

Return Value

Type: System.String
The ID of the cache item that contains the chart.

The following example shows how to save a chart to cache using the SaveToCache method.

    var chartKey = Request["key"]; 
    if (chartKey != null) { 
        var cachedChart = Chart.GetFromCache(key: chartKey); 
        if (cachedChart == null) { 
            cachedChart = new Chart(600, 400); 
            cachedChart.AddTitle("Cached Chart -- Cached at " + DateTime.Now); 
               name: "Employee", 
               axisLabel: "Name", 
               xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
               yValues: new[] { "2", "6", "4", "5", "3" }); 
            cachedChart.SaveToCache(key: chartKey,  
               minutesToCache: 2,  
               slidingExpiration: false); 

  • Medium trust for the immediate caller. This member can be used by partially trusted code.