Non-web version of System.Web.Caching.Cache

S

Steve W

I have an ASP.NET app that calls into some VB.NET components. It passes in
the current application's cache (HttpContext.Current.Cache).

These VB.NET components also get called by a non-ASP.NET application (in
this case a VB.NET windows service). I'd like to create something like the
cache in this service to hold application-wide information (like database
connection strings) and then pass that into the components.

As a test, I tried creating a 'new' System.Web.Caching.Cache object in a
test VB.NET windows app, but I get an error when I try and insert something
into the Cache object created in this way (System.NullReferenceException)
which I assume is because I'm not in a proper HTTP Context etc.

Any suggestions as to the best way to architect this ?

Thanks

Steve
 
K

Karl Seguin

Instead of passing in the cache, simply use
HttpRuntime.Cache from the components...you'll need to include the
system.web dll..but everything should work..

Karl
 
S

Steven Cheng[MSFT]

Hi Steve,

Thanks for your posting. As for the HttpContext.Cache or the
System.Web.Caching.Cache class, it is a particular class which is designed
to be used only in ASP.NET enviroment, also, each ASP.NET web application
will has a global cache itself, so when the Cache class instance need to
have a HttpContext to associate with it. Also, we can't directly use it in
a non-ASP.NET appliation since there is no ASP.NET host environment in
those application. If you do need to do some caching work in non-asp.net
application, we may need to implement our own caching mechanism. The
Caching Application Block in MS's application blocks provide such a custom
caching framework, you may have a look to see whether it helps:

#Caching Application Block
http://msdn.microsoft.com/library/en-us/dnpag2/html/caching1.asp?frame=true

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top