ASP.NET Caching Question:
Download Job Interview Questions and Answers PDF
Do you know about caching with the DataSource Controls?
Answer:
The DataSource controls enable you to cache database data while connecting a .NET application to a database. The DataSource control provides various properties, such as EnableCaching, which you can use to automatically cache the data represented by a DataSource control. The syntax to cache a database table in a memory for 120 seconds is:
<asp:SqlDataSource ID=”SqlDataSource1” EnableCaching=”True” CacheDuration=”120”
ConnectionString=”Server=localhost;database=AdventureWorks;uid=user;pwd=word;”
SelectCommand=”SELECT * FROM Production.ProductCategory” Runat=”server”/>
The above syntax caches a database table, ProductCategory, by setting the EnableCaching property of the DataSource control to True. The CacheDuration property of the DataSource control specifies the time, in seconds, for caching the data before it is updated in a database containing the ProductCategory table. The value of the Time parameter is set to 120 to cache data for two minutes.
<asp:SqlDataSource ID=”SqlDataSource1” EnableCaching=”True” CacheDuration=”120”
ConnectionString=”Server=localhost;database=AdventureWorks;uid=user;pwd=word;”
SelectCommand=”SELECT * FROM Production.ProductCategory” Runat=”server”/>
The above syntax caches a database table, ProductCategory, by setting the EnableCaching property of the DataSource control to True. The CacheDuration property of the DataSource control specifies the time, in seconds, for caching the data before it is updated in a database containing the ProductCategory table. The value of the Time parameter is set to 120 to cache data for two minutes.
Download ASP.NET Caching Interview Questions And Answers
PDF
Previous Question | Next Question |
Do you know Caching Feature? | Do you know using SQL Cache Invalidation? |