Caching Concepts
Can you compare ASP.NET sessions with classic ASP?
Dec 5th
ASP.NET session caches per user session state. It basically uses “HttpSessionState” class.
Following are the limitations in classic ASP sessions :-
? ASP session state is dependent on IIS process very heavily. So if IIS restarts ASP session variables are also recycled.ASP.NET session can be independent of the hosting environment thus ASP.NET session can maintained even if IIS reboots.
? ASP session state has no inherent solution to work with Web Farms.ASP.NET session can be stored in state server and SQL SERVER which can support multiple server.
? ASP session only functions when browser supports cookies.ASP.NET session can be used with browser side cookies More >
What are dependencies in cache and types of dependencies ?
Dec 5th
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 More >
What is Cache Callback in Cache ?
Dec 5th
Cache object is dependent on its dependencies example file based, time based etc…Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.
Can you show a simple code showing file dependency in cache ?
Dec 5th
Partial Class Default_aspx
Public Sub displayAnnouncement() Dim announcement As String
If Cache(“announcement”) Is Nothing Then Dim file As New _
System.IO.StreamReader _
(Server.MapPath(“announcement.txt”)) announcement = file.ReadToEnd file.Close()
Dim depends As New _
System.Web.Caching.CacheDependency _ (Server.MapPath(“announcement.txt”))
Cache.Insert(“announcement”, announcement, depends)
End If
Response.Write(CType(Cache(“announcement”), String)) End Sub
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
displayAnnouncement()
End Sub
End Class
Note :- Above source code can be obtained from CD in “CacheSample”
folder.”Announcement.txt” is in the same folder which you can play around to see the results.
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 More >
What is an application object ?
Dec 5th
Application object ca be n used in situation where we want data to be shared across users globally.