asp.net interview questions: cache
(1) what is the difference between Cache object and application object?
The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.
(2) What are dependencies in cache and types of dependencies?
When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies. Example if the cache object is dependent on file and when the file data changes you want the cache object to be update. Following are the supported dependency:-
. File dependency: - Allows you to invalidate a specific cache item when a disk based file or files change.
. Time-based expiration: - Allows you to invalidate a specific cache item depending on predefined time.
. Key dependency:- Allows you to invalidate a specific cache item depending when another cached item changes.
(3) How can get access to cache object?
The Cache object is defined in the 'System.Web.Caching' namespace. You can get a reference to the Cache object by using the Cache property of the Http Context class in the 'System.Web' namespace or by using the Cache property of the Page object.
ASP.NET Interview Questions: Query Strings
A query string is information sent to the server appended to the end of a page URL.
Following are the benefits of using query string for state management:-
. No server resources are required. The query string containing in the HTTP requests for a specific URL.
. All browsers support query strings.
Following are limitations of query string:-
. Query string data is directly visible to user thus leading to security problems.-
. Most browsers and client devices impose a 255-character limit on URL length.
Below is a sample "Login" query string passed in URL http://www.jack-fx.com.com/login.asp?login=testing.
This query string data can then be requested later by using Request.QueryString("login").
(I) 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 that the cache will have a sliding duration of one minute. If a request is made 59 seconds after the cache is accessed, the validity of the cache would be reset to another minute:
Cache.Insert("announcement", announcement, depends, _
Date Time. Max Value, _
TimeSpan.FromMinutes(1))
How can you cache different version of same page using ASP. NET cache object?
Output cache functionality is achieved by using "OutputCache" attribute on ASP. NET page header. Below is the syntax
1: <%@ Output Cache Duration="20" Location="Server" Vary By Param="state" Vary By Custom="minor version" Vary By Header="Accept-Language"%>
-
Vary By Param: - Caches different version depending on input parameters send through HTTP POST/GET.
-
Vary By Header: - Caches different version depending on the contents of the page header.
-
Vary By Custom: -Lets you customize the way the cache handles page variations by declaring the attribute and overriding the Get Vary By Custom String handler.
-
Vary By Control: -Caches different versions of a user control based on the value of properties of ASP objects in the control.
Asp.net Interview Question: What are dependencies in cache and types of dependencies?
When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies. Example if the cache object is dependent on file and when the file data changes you want the cache object to be update. Following are the supported dependency:-
-
File dependency: - Allows you to invalidate a specific cache item when a disk based file or files change.
-
Time-based expiration: - Allows you to invalidate a specific cache item depending on predefined time.
-
Key dependency:- Allows you to invalidate a specific cache item depending when another cached item changes.