Wednesday, March 28, 2012

The Cache object

Hello!

Is there a way to get to the Cache object in some other way than the
current contex?
I mean - the Cache is independant from the request so I would expect to
see some kind of Cache.Current property or something like
HttpContext.Current, but unfortunately I've been unable to find one.
When it could be usefull is for example a situation when I put some
task to be done every few minutes on the server - independent from the
requests comming in.
The way I do it now is to catch one of the Requests, get the Cache from
there and store the reference to it in some global/static variable.

--
MichalHttpRuntime.Cache

You might need to reference the System.Web assembly, but you can use it for
any type of application, including windows forms, console, web service...

Karl

--
http://www.openmymind.net/

"Mikeon" <mikeon@dotnet.itags.org.icpnet.pl> wrote in message
news:1142928776.985959.270680@dotnet.itags.org.u72g2000cwu.googlegr oups.com...
> Hello!
> Is there a way to get to the Cache object in some other way than the
> current contex?
> I mean - the Cache is independant from the request so I would expect to
> see some kind of Cache.Current property or something like
> HttpContext.Current, but unfortunately I've been unable to find one.
> When it could be usefull is for example a situation when I put some
> task to be done every few minutes on the server - independent from the
> requests comming in.
> The way I do it now is to catch one of the Requests, get the Cache from
> there and store the reference to it in some global/static variable.
> --
> Michal
Hello!

Yep, I'm already referencing it, but! What I need is a way to get the
Cache object without the Context object which is only available during
request processing which is not allways the case when some code on the
server runs as in my example with tasks running on the server every few
minutes. The importatnt part is that the tasks are run even if no one
uses my application i.e.: no one is requesting pages at the moment and
there is some Timer object stored in the Application state which fires
some tasks.

--
Michal
Not sure if you read what I said, but you can use the HttpRuntime.Cache
which IS available even without a context..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/

"Mikeon" <mikeon@dotnet.itags.org.icpnet.pl> wrote in message
news:1142945004.761815.70410@dotnet.itags.org.z34g2000cwc.googlegro ups.com...
> Hello!
> Yep, I'm already referencing it, but! What I need is a way to get the
> Cache object without the Context object which is only available during
> request processing which is not allways the case when some code on the
> server runs as in my example with tasks running on the server every few
> minutes. The importatnt part is that the tasks are run even if no one
> uses my application i.e.: no one is requesting pages at the moment and
> there is some Timer object stored in the Application state which fires
> some tasks.
> --
> Michal
Thus wrote Mikeon,

> Hello!
> Is there a way to get to the Cache object in some other way than the
> current contex?
> I mean - the Cache is independant from the request so I would expect
> to
> see some kind of Cache.Current property or something like
> HttpContext.Current, but unfortunately I've been unable to find one.
> When it could be usefull is for example a situation when I put some
> task to be done every few minutes on the server - independent from the
> requests comming in.
> The way I do it now is to catch one of the Requests, get the Cache
> from
> there and store the reference to it in some global/static variable.

You can also consider using the Caching Application Block in EL 2.0. The
API is similar to ASP.NET's Cache class.

Cheers,
--
Joerg Jooss
news-reply@dotnet.itags.org.joergjooss.de
Hello!

Oh! I've missed this first line of yours. Of course it is what I was
looking for.
Thank you!

--
Michal

0 comments:

Post a Comment