By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,103 Members | 1,488 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,103 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Steve W" <Bu*********@community.nospam> wrote in message
news:Ow**************@TK2MSFTNGP15.phx.gbl...
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

Nov 19 '05 #2

P: n/a
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...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.)

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.