use below example for it
protected void Page_Load(object sender, EventArgs e)
{
Response.AddCacheItemDependency("ProcessIntensiveReport");
// Set additional properties to enable caching.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
}
File-based Dependency
File-based dependency invalidates a particular Cache item when file(s) on disk change. For example, if instead of loading our ProductData from a database, we loaded it from an XML file:
Dim dom As XmlDocument()
dom.Load(Server.MapPath("product.xml")
Cache("ProductData") = dom
We obviously would also want to invalidate the data within the Cache if product.xml changes. Assuming product.xml is in the same directory as the requesting application:
Dim dependency as new CacheDependency(Server.MapPath("product.xml"))
Cache.Insert("ProductData", dom, dependency)
In the above code sample, we're creating an instance of a CacheDependency class, dependency, and passing in the path to the product.xml file. We then use the Insert() method of the Cache to create our ProductData key that is dependent upon the file it retrieves its data from.
Key-based Dependency
Key-based dependency invalidates a particular Cache item when another Cache item changes. For example, if our application added multiple DataSets to the Cache, such as ProductData, SalesData, and MarketingData and SalesData and MarketingData rely upon ProductData being valid. We could use a key-based dependency to invalidate SalesData and MarketingData if ProductData changes. We set up this dependency when we create the Cache entries for SalesData and MarketingData:
Dim dependency (1) As String
dependencyKey(0) = "ProductData"
Dim productDataDependency As new CacheDependency(nothing, dependencyKey)
Cache.Insert("SalesData", LoadDataSet("Sales"), productDataDependency)
In the above example code, we use the Insert() method to create a new Cache entry named SalesData passing in an instance of a CacheDependency class named productDataDependency which names the Cache key ProductData. Now, whenever ProductData changes, SalesData will be removed from the Cache.
Time-based Dependency
Time-based dependency simply expires the item at a defined point in time. Again, we would use the Insert() method of the Cache to create this dependency. We have two options for time-based dependency:
•Absolute—Sets an absolute time; for example, current time + 10 minutes for the Cache entry to expire.
•Sliding—Resets the time for the item in the Cache to expire on each request.
We can use the Sliding expiration option to Cache our ProductData DataSet for a maximum of 10 minutes. As long as requests for ProductData are made within a 10-minute window, the data is made valid for another 10 minutes:
' 10 minute time span
Dim span As New TimeSpan(0,10,0)
Cache.Insert("ProductData", LoadDataSet(), nothing, nothing, span)