.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 >> C# >> Post New Question Subscribe to Interview Questions

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

Posted By :shah268     Posted Date :November 26, 2009    Points :10   Category :C# 
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

}

You can also find related Interview Question to Is it possible to notify application when item is removed from cache ?  below: 

what is session ,cache, cookie, application memory timeout?

  

Session timeout: 20 min
Cache timeout: duration we have to specify.
Cookie: for in memory cookie till browser opened
For persistent cookie timeout is till expires property's time .
Application memory timeout: till appdomain exist (More...)

Difference between Cache object and application object ?

  
Difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies. (More...)

Explain the difference between cache object and application object.

  
Application Object: Application variable/object stores an Object with a scope of availability of the entire Application unless explicitly destroyed.

Caching Object: The lifetime of cache is throughout the lifetime of an application or is based upon timeouts (More...)

What is Application Domain?

  
The primary purpose of the AppDomain is to isolate an application from other applications. Win32 processes provide isolation by having distinct memory address spaces. This is effective, but it is expensive and doesn't scale well. The .NET runtime enforces AppDomain isolation by keeping control over the use of memory - all memory in the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each other's memory.
Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, or by using a proxy to exchange messages.
MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries. (More...)

I have written an assembly that I want to use in more than one application. Where do I deploy it?

  
Assemblies that are to be used by multiple applications (for example, shared assemblies) are deployed to the global assembly cache. In the prerelease and Beta builds, use the /i option to the Alink SDK tool to install an assembly into the cache:
al /i:myDll.dll
A future version of the Windows Installer will be able to install assemblies into the global assembly cache. (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...)

What is an application domain?

  
An application domain (often AppDomain) is a virtual process that serves to isolate an application. All objects created within the same application scope (in other words, anywhere along the sequence of object activations beginning with the application entry point) are created within the same application domain. Multiple application domains can exist in a single operating system process, making them a lightweight means of application isolation.
An OS process provides isolation by having a distinct memory address space. While this is effective, it is also expensive, and does not scale to the numbers required for large web servers. The Common Language Runtime, on the other hand, enforces application isolation by managing the memory use of code running within the application domain. This ensures that it does not access memory outside the boundaries of the domain. It is important to note that only type-safe code can be managed in this way (the runtime cannot guarantee isolation when unsafe code is loaded in an application domain). (More...)

Describe the techniques for optimising your application?

  
. Avoid round-trips to server. Perform validation on client.
. Save viewstate only when necessary.
. Employ caching.
. Leave buffering on unless there is a dire need to disable it.
. Use connection pooling.
. Use stored procedures instead of in-line SQL or dynamic SQL. (More...)

Differences between application and session.

  
The session object maintains state on a per client basis whereas the application object is on a per application basis and is consistent across all client requests. (More...)

What is web application virtual directory?

  
A virtual directory appears to client browsers as though it were
contained in a Web server's root directory, even though it can physically Reside somewhere else. (More...)

what is different between session and application

  
session is a object that store information between http request for a paticular user.
->But application object are global for each user (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 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...)

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...)

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