Caching Concepts

Why do we need methods to be static for Post Cache substitution?

ASP.NET should be able to call this method even when there isn’t an instance of your page class available. When your page is served from the cache, the page object isn’t created. So ASP.NET skips the page life cycle when the page is coming from cache, which means it won’t create any control objects or raise any control events. If your dynamic content depends on the values of other controls, you’ll need to use a different technique, because these control objects won’t be available to your callback

What is Post Cache substitution?

Post cache substitution is used when we want to cache the whole page but also need some dynamic region inside that cached page. Some examples like QuoteoftheDay, RandomPhotos, and AdRotator etc. are examples where we can implement Post Cache Substitution.

Post-cache substitution can be achieved by two means:

?   Call the new Response.WriteSubstitution method, passing it a reference to the desired substitution method callback.

?   Add a <asp:Substitution> control to the page at the desired location, and set its methodName attribute to the name of the callback method.

What is SQL Cache Dependency in ASP.NET 2.0?

SQL cache dependencies is a new feature in ASP.NET 2.0 which can automatically invalidate a cached data object (such as a Dataset) when the related data is modified in the database. So for instance if you have a dataset which is tied up to a database tables any changes in the database table will invalidate the cached data object which can be a dataset or a data source.

How do we enable SQL Cache Dependency in ASP.NET 2.0?

Below are the broader steps to enable a SQL Cache Dependency:-

•       Enable notifications for the database.

•       Enable notifications for individual tables.

•       Enable ASP.NET polling using “web.config” file

•       Finally use the Cache dependency object in your ASP.NET code

Enable notifications for the database.

Before you can use SQL Server cache invalidation, you need to enable notifications for the database. This task is performed with the aspnet_regsql.exe command-line utility, which is located in the c:\[WinDir]\Microsoft.NET\Framework\[Version] directory.

aspnet_regsql -ed -E -d Northwind

-ed :- command-line switch

-E: – Use trusted connection

-S: – Specify server name it other than the current computer you are working on

-d: – Database Name

So More >

Can we post and access view state in another application?

You can post back to any page and pages in another application, too. But if you are posting pages to another application, the PreviousPage property will return null. This is a significant restriction, as it means that if you want to use the view state, you are confined, for example, to posting to pages in the same virtual directory. Even so, this is a highly acceptable addition to the functionality of ASP.NET.

How do we access viewstate value of this page in the next page ?

View state is page specific; it contains information about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name, __POSTBACK . This field is embedded only when there is an IButtonControl on the page and its PostBackUrl property is set to a non-null value. This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new PreviousPage property of the page:

Page poster = this.PreviousPage;

Then you can find any control from the previous page and read its state:

Label posterLabel = poster.findControl(“myLabel”);

string More >

What is cross page posting?

By default, button controls in ASP.NET pages post back to the same page that contains the button, where you can write an event handler for the post. In most cases this is the desired behavior, but occasionaly you will also want to be able to post to another page in your application. The Server.Transfer method can be used to move between pages, however the URL doesn’t change. Instead, the cross page posting feature in ASP.NET 2.0 allows you to fire a normal post back to a different page in the application. In the target page, you can then access the More >

What is Absolute and Sliding expiration?

Absolute Expiration allows you to specify the duration of the cache, starting from the time the cache is activated. The following example shows that the cache has a cache dependency specified, as well as an expiration time of one minute.

Cache.Insert(“announcement”, announcement, depends, _

DateTime.Now.AddMinutes(1), Nothing)

Sliding Expiration specifies that the cache will expire if a request is not made within a specified duration. Sliding expiration policy is useful whenever you have a large number of items that need to be cached, because this policy enables you to keep only the most frequently accessed items in memory. For example, the following code specifies More >

What are benefits and limitations of using Cookies?

Following are benefits of using cookies for state management :-

?   No server resources are required as they are stored in client. ?   They are light weight and simple to use

Following are limitation of using cookies :-

?   Most browsers place a 4096-byte limit on the size of a cookie, although support for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.

?   Some users disable their browser or client device’s ability to receive cookies, thereby limiting the use of cookies.

?   Cookies can be tampered and thus creating a security hole. ?   Cookies can expire thus leading More >

Where do you specify session state mode in ASP.NET?

<sessionState mode=”SQLServer”

stateConnectionString=”tcpip=192.168.1.1:42424″

sqlConnectionString=”data source=192.168.1.1; Integrated Security=SSPI”

cookieless=”false” timeout=”20″

/>

Above is sample session state mode specified for SQL SERVER