views:

302

answers:

1

Hi, Currently, I created my custom PerWebRequestLifetimeManager using HttpContext.Current.Items as backing store. I used that lifetime manager for Linq2Sql DataContext.
Eveything is working fine until I need to use Cache for storing data (for 5 min). After 5 min, I need to retrieve data from DB and put it into the Cache. To do so, I need to use Linq2Sql DataContext for retrieving data. But during that time, HttpContext.Current is null because which was happened when cache is expired; not in Web Request.
So, what kind of LifetimeManager should I use for this scenario?

Thanks in advance.

A: 

You need a long standing DataConext? Use a Container LifeTimeManager. I would create a Container that resides at the Application level (probably in your Global.asax) and then use that to resolve your DataContext for this specific scenario.

I would avoid hoping that stuff is retained in Cache, instead you could look at possibly running that task asynchronously if you can.

Hope this helps.

Khalid Abuhakmeh