.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> ASP.Net >> Post New Question Subscribe to Interview Questions

What is SQL Cache Dependency in ASP.NET?

Posted By :Jack Smith     Posted Date :October 09, 2012    Points :40   Category :ASP.Net 
SQL Cache Dependency in ASP.NET: It is the mechanism where the cache object gets invalidated when the related data or the related resource is modified. It is a feature in SQL Server 2005 and SQL Server 2000.

3 types of SQL-cache dependencies exist:

a. Other cache items.
b. Files/folders.
c. Dependencies on a database query.

You can also find related Interview Question to What is SQL Cache Dependency in ASP.NET?  below: 

What is SQL Cache Dependency in ASP.NET?

  
SQL cache dependencies is new technique in ASP.NET 2.0 onwards which can automatically invalidate a cached data object just like 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.

To enable this we need a syntax that is as follows in visual studio command prompt type the following command

aspnet_regsql -ed -E -d (More...)

How can I see what assemblies are installed in the global assembly cache?

  
The .NET Framework ships with a Windows shell extension for viewing the assembly cache. Navigating to % windir%\assembly with the Windows Explorer activates the viewer. (More...)

where is global assembly cache location in system?

  
The .NET Framework ships with a Windows shell extension for viewing the assembly cache. Navigating to % windir%\assembly with the Windows Explorer activates the viewer. (More...)

What are Cache - Dependencies types?

  
When anyone add an item to cache, he/she can define the dependency relationships that can force that item to be removed from the cache under specific activities of dependencies.

For example: If the cache is dependent on file and when the file data changes you want the cache object to be updated.

Following are the difference dependencies:
(a) File Dependency :
Allows invalidating a specific cache item when a disk based file or files change.
object errorData;
//Load errorData from errors.xml

CacheDependency fileDependency =
new CacheDependency(Server.MapPath("errors.xml"));
Cache.Insert("ERROR_INFO", errorData, fileDependency);

(b) Time based expiration :
Allows to invalidate a specific cache item depending on predefined time.


//Absolute Expiration

Cache.Insert("EMP_NAME", "Shubhabrata", null,
DateTime.Now.AddDays(1), Cache.NoSlidingExpiration);

//Sliding Expiration

Cache.Insert("EMP_NAME", "Shubhabrata", null,
Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(60));


(c) Key dependency :
Allows to invalidate a specific cache item depending when another cache item changes.


string[] relatedKeys = new string[1];
relatedKeys[0] = "EMP_NUM";
CacheDependency keyDependency = new CacheDependency(null, relatedKeys);
Cache["EMP_NUM"] = 5435;
Cache.Insert("EMP_NAME", "Shubhabrata", keyDependency);
Cache.Insert("EMP_ADDR", "Bhubaneswar", keyDependency);
Cache.Insert("EMP_SAL", "5555USD", keyDependency); (More...)

Can you place two .dll files with the same name in GAC (Global Assembly Cache)?

  
Yes, provided both have different versions.
GAC is a Folder that contains .dll that have strong name. So we can keep myproject.dll and myproject.dll two files into GAC with different version like 1.0.0.0 and 1.0.0.1 (More...)

Is the ASP.NET AJAX Control Toolkit(AjaxControlToolkit.dll) installed in the Global Assembly Cache?

  
No. You must copy the AjaxControlToolkit.dll assembly to the /Bin folder in your application. (More...)

How can you cache Multiple Versions of a Page?

  
Using output cache you can cache multiple versions of the page.

We can either use,.

- @ OutputCache directive at design time declaratively for Declarative Approach
OR

- Response.Cacheclass at runtime for Programmatic Approach .

With @ OutputCache directive four parameters of VaryByParam , VaryByControl, VaryByHeader, VaryByCustom allows user to cache page depending on query string, control value, request's HTTP header, request's HTTP header respectively.

For an example:

To turn off caching,

Declarative Approach:
<%@ OutputCache Location="None" VaryByParam="None" %>

Programmatic Approach:
Response.Cache.SetCacheability(HttpCacheability.NoCache);


To cache the output for each HTTP request that arrives with a different ID:

Declarative Approach:
<%@ OutputCache duration="60" varybyparam=" ID" %>

Programmatic Approach:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.VaryByParams["ID"] = true; (More...)

Is it possible to notify application when item is removed from cache ?

  
Yes.

You can use CacheItemRemovedCallback delegate defining signature for event handler to call when item is removed from cache.

For an example:

HttpRuntime.Cache.Insert(
"CacheItem1", //insert cache item
"",
null,
Cache.NoAbsoluteExpiration,
new TimeSpan(0, 0, 15),
CacheItemPriority.Default,
new CacheItemRemovedCallback(RemovalMethod)); //define method which needs to be called when item is removed from cache

The method will be like,
private static string RemovedAt = string.Empty;
public static void RemovalMethod(String key, object value, //method is declared static so that it can be available when cache item is deleted
CacheItemRemovedReason removedReason)
{

RemovedAt = "Cache Item Removed at: " + DateTime.Now.ToString(); //Shows the time when cache item was removed

} (More...)

What is difference between System.Web.Caching.Cache and System.Web.HttpContext.Current.Cache ?

  
System.Web.Caching.Cache : Class/type used for caching
System.Web.HttoContect.Current.Cache : The instance of cache class for current HTTP context from a web request (Gets cache object from current application domain) (More...)

What are dependency properties?

  
Using the properties of a class into another class is called as dependency properties (More...)

How can we get the path of the internet cache?

  
Using the following code

Environment.SpecialFolder.InternetCache (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend