26.02.2015 Views

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

(P)Can you show a simple code showing file dependency in cache ?<br />

Partial Class Default_aspx<br />

Public Sub displayAnnouncement()<br />

Dim announcement As String<br />

If Cache(“announcement”) Is Nothing Then<br />

Dim file As New _<br />

System.IO.StreamReader _<br />

(Server.MapPath(“announcement.txt”))<br />

announcement = file.ReadToEnd<br />

file.Close()<br />

Dim depends As New _<br />

System.Web.Caching.CacheDependency _<br />

(Server.MapPath(“announcement.txt”))<br />

Cache.Insert(“announcement”, announcement, depends)<br />

End If<br />

Response.Write(CType(Cache(“announcement”), String))<br />

End Sub<br />

Private Sub Page_Init(ByVal sender As Object, ByVal e As<br />

System.EventArgs) Handles Me.Init<br />

displayAnnouncement()<br />

End Sub<br />

End Class<br />

Note :- Above source code can be obtained from CD in “CacheSample”<br />

folder.”Announcement.txt” is in the same folder which you can play around to see the<br />

results.<br />

Above given method displayAnnouncement() displays banner text from Announcement.txt<br />

file which is lying in application path of the web directory.Above method first checks is<br />

the Cache object nothing , if the cache object is nothing then it moves further to load the<br />

cache data from the file.Whenever the file data changes the cache object is removed and<br />

set to nothing.<br />

(A) What is Cache Callback in Cache ?<br />

Cache object is dependent on its dependencies example file based , time based etc.Cache<br />

items remove the object when cache dependencies change.ASP.<strong>NET</strong> provides capability<br />

to execute a callback method when that item is removed from cache.<br />

89

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!