?

Log in

Previous Entry | Next Entry

ASP.NET interview questions: - What are dependencies in cache & types of dependencies? Also show a simple code showing file dependency in cache?

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.

Below is simple code showing file dependency in cache: -

PartialClass Default_aspx

PublicSub displayAnnouncement()
Dim announcement AsString
If Cache(“announcement”) IsNothingThen
Dim file AsNew _
System.IO.StreamReader _
 (Server.MapPath(“announcement.txt”))
announcement = file.ReadToEnd
file.Close()
Dim depends AsNew _
System.Web.Caching.CacheDependency _
 (Server.MapPath(“announcement.txt”))
Cache.Insert(“announcement”, announcement, depends)
EndIf
Response.Write(CType(Cache(“announcement”), String))
EndSub

PrivateSub Page_Init(ByVal sender AsObject, ByVal e As
      System.EventArgs) HandlesMe.Init
displayAnnouncement()
EndSub
End Class


Above given method displayAnnouncement() displays banner text from Announcement.txt file which is lying in application path of the web directory. Above method, first checks whether the Cache object is nothing, if the cache object is nothing then it moves further to load the cache data from the file. Whenever the file data changes the cache object is removed and set to nothing.

Above is the ASP.NET interview questions & see following video on creating master pages in ASP.NET: -

Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

March 2017
S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Tags

Powered by LiveJournal.com