views:

93

answers:

3

I'm creating a ASP.NET MVC 2 application that envolve a section like questions here in stackoverflow (mine is with exams is another kind of application but can be extrapolate to same general idea of SO).

OK I'm creating a cache per page, its mean something like this:

[OutputCache(Duration=60, VaryByParam="page")]
ActionResult AllQuestions(int page){...}

But i want to invalidate that cache when a new question is created. What can i do.

I'm open to suggestions, perhaps this is not the best way to solve this problem

+4  A: 

If your questions are stored in a SQL database you could setup an SQL expiration policy so that when data changes the cache will expire.

Darin Dimitrov
A: 

Darin is correct. Additionally, if you don't have SQL Server, or don't want to use it as the cache dependency, you can create a custom cache dependency, as 15seconds has a tutorial on: http://www.15seconds.com/issue/040518.htm

Paul
A: 

Remember, there are only two hard problems in computer science, and cache invalidation is one them. Don't add the trouble of caching until you need it. As always, avoid premature optimization like this.

kevingessner