Cache like stackoverflow
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
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 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
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.
精彩评论