views:

288

answers:

1

I have an ASP.Net MVC web app that includes a set of Forums. In order to maintain flexible security, I have chosen an access-control-list style of security.

However, this is getting to be a pretty heavy chunk of data to retrieve every time somebody views the forum index.

I am using the EnterpriseLibrary.Caching functionality to cache various non-LINQ items on the site. (The BBCode interpreter, the Skins, and etc.)

My question is this:

What is the safest and most elegant way to cache a LINQ result?

Essentially, I would like to keep a copy of the ACL for each forum in memory to prevent the database hit. That way, for each person that hits the site, at most I would have to fetch group membership information.

All-in-all I'm really looking for a way to cache large abouts of LINQ data effectively, not just these specific rows.

+1  A: 

If you've already got a caching system for general objects, all you should need is this:

var whatever = linkQuery.ToList();
John Fisher
Won't that prevent the garbage collector from calling the destructor of the DataContext? I'm disposing of it properly, but I don't want it hanging around if I don't need to.
John Gietzen
It shouldn't prevent garbage collection of the datacontext. The entity objects have no reference back to the DC. (The DC's change tracker may have a reference to the entity objects, but there's no reference back... ....so it shouldn't prevent a disposed dc from getting gc'd)
KristoferA - Huagati.com
Perfect, thanks!
John Gietzen