S
Sunish Abraham
I need to adding caching capability to our application and we "get" data
from our business layer code ; so initially I wanted to use something in
..Net framework that provided caching and found that the "caching" mechanism
was implemented in System.Web ; initially I didn't want to add System.Web
reference to our business object because it was used from our web
applications as well as WinForm, console applications ; so I thought I would
handle the "checking" to see if the business object was running in the
HttpContext and then use System.Web.HttpRunTime.Cache (if in ASP.NET) or
EntLib Caching (other) ; I wanted to test something, so I created a console
application and a classlibrary ; in the classlibrary, I referenced
system.web and added the following shared method:
Public Shared Function GetData() As String
Dim strCachedInfo As String =
CType(System.Web.HttpRuntime.Cache("CACHEDINFO"), String)
If strCachedInfo Is Nothing Then
strCachedInfo = "Hello world..."
System.Web.HttpRuntime.Cache.Insert("CACHEDINFO", strCachedInfo,
Nothing, DateTime.Now.AddSeconds(15), TimeSpan.Zero)
End If
Return (strCachedInfo)
End Function
and in the console application, i referenced the classlibrary and called the
GetData method...
Console.WriteLine(ClassLibrary1.Class1.GetData())
to my confusion, it worked?? ; I don't understand why if the classlibrary
was running in the "context" of the console process did i not get an
exception when calling System.Web.HttpRuntime.Cache? I read that http
context was implemented using
System.Runtime.Remoting.Messaging.CallContext...does this have something
with why this worked? am I not understanding the caching mechanism
correctly? thanks for light you can shed on this!!
Sunish Abraham
from our business layer code ; so initially I wanted to use something in
..Net framework that provided caching and found that the "caching" mechanism
was implemented in System.Web ; initially I didn't want to add System.Web
reference to our business object because it was used from our web
applications as well as WinForm, console applications ; so I thought I would
handle the "checking" to see if the business object was running in the
HttpContext and then use System.Web.HttpRunTime.Cache (if in ASP.NET) or
EntLib Caching (other) ; I wanted to test something, so I created a console
application and a classlibrary ; in the classlibrary, I referenced
system.web and added the following shared method:
Public Shared Function GetData() As String
Dim strCachedInfo As String =
CType(System.Web.HttpRuntime.Cache("CACHEDINFO"), String)
If strCachedInfo Is Nothing Then
strCachedInfo = "Hello world..."
System.Web.HttpRuntime.Cache.Insert("CACHEDINFO", strCachedInfo,
Nothing, DateTime.Now.AddSeconds(15), TimeSpan.Zero)
End If
Return (strCachedInfo)
End Function
and in the console application, i referenced the classlibrary and called the
GetData method...
Console.WriteLine(ClassLibrary1.Class1.GetData())
to my confusion, it worked?? ; I don't understand why if the classlibrary
was running in the "context" of the console process did i not get an
exception when calling System.Web.HttpRuntime.Cache? I read that http
context was implemented using
System.Runtime.Remoting.Messaging.CallContext...does this have something
with why this worked? am I not understanding the caching mechanism
correctly? thanks for light you can shed on this!!
Sunish Abraham