Cache Policy Advice

W

Weston Weems

I attempted to post this yesterday however I dont see that
it ever made it up. If this is an error on my part, I
apologize in advance.

I've got a webapp with somewhat trivial amount of data,
however aquiring the data from the database usually takes
approximately 1.5minutes. So first thing that pops into my
head is cache it.

What I'd like to do is load the cache up on
Application_Start, then refresh every 4hrs or so. I'd like
to avoid handling it lazily, because that guarentees one
person will need to wait 1.5 minutes, whereas if it was
just refreshed every 4hrs on the backend, that condition
may occur, and it may not.

I've got no problem loading up data on application_start,
and set a CacheItemRemovedCallBack to execute a method to
reload the cache with the data. The problem I am
encountering is that I cant get a HttpContext to pull the
cache object from.

Should I be doing this a better way, or anyone have any
sort of advice whatsoever? Source samples?

Thanks in advance,
Weston Weems
 
D

Dimitri Glazkov

Weston,

Where exactly in the code are you having a problem with retrieving the
HttpContext instance?

:DG<
 
K

Kevin Spencer

Use System.Web.HttpRuntime.Cache. This static property of the Application
class returns the Cache.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
W

Weston Weems

I've set up

MyNamespace.Caching - as a simple class that contains a
few methods to set/purge cache items, as well as
containing CacheItemRemovedCallBack.

I do MyCache.Caching.AddCacheItem(object item)

which will insert with a expriation of now+4hrs, and a
CacheItemRemovedCallBack which is also in my Caching
namespace.

The problem is it loads initially, but when it goes to
refresh, it gives me a null reference exception for some
strange reason.

If I've got the wrong idea, does anyone have examples of
how one might achieve this?

thank you very much.
Weston Weems
 
W

Weston Weems

Thank you this was exactly the sort of thing I was looking
for.
I'll give it a whirl.
 
W

Weston Weems

Thank you, that worked perfectly!
Weston

-----Original Message-----
Use System.Web.HttpRuntime.Cache. This static property of the Application
class returns the Cache.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.




.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top