Question

I'm working on an ASP.NET Web Pages project using Razor 3 and targeting .NET framework 4.5. At this point I don't know if it will be deployed on IIS7 (Windows Server 2008 R2) or on IIS8 (Windows Server 2012).

I have some .vbhtml content pages which are populated from a database managed by a bespoke CMS. The content of these pages will change infrequently (they are home page, about us, how it works, FAQ type pages) and I want to make sure the content is cached effectively to prevent unnecessary database calls. I think of this as semi-dynamic content.

What is the best way to go about caching the pages such that they only fetch from the database when the content there has been changed? Can this be set up in IIS or should it be done in code?

Thanks.

Was it helpful?

Solution

I'll preface this by saying that I am by no means an expert on caching, the following just represents my opinions and thoughts on your issue.

Firstly, the case for not using caching at all. By using caching we basically trade CPU and I/O time for memory footprint. If the former are at a premium and you have the latter spare, it is an obvious win. Of course it does come at another price, additional to the memory usage: code complexity. A caching system certainly doesn't have to be overly complex, but I've always been of the opinion that very often the best code you can write is the simplest code you can write. My personal take on the matter is that before even considering implementing caching of dynamic resources those resources should be being requested more than once per minute (or the page should be calculating something extremely expensive CPU or I/O-wise). If the code is being executed infrequently I would say a simple CMS database hit for some content every so often just isn't worth adding an additional point of failure to a codebase.

That said, and continuing with the assumption that you still want to implement some form of basic cache system on your site, Web Pages provides some simple but robust built in tools. Here's a good tutorial:

http://www.asp.net/web-pages/tutorials/performance-and-traffic/15-caching-to-improve-the-performance-of-your-website

The reason I asked about whether the CMS uses the same project is that it's sometimes handy when you can easily make the editor directly invalidate/reload the cache when a particular piece of content is edited. You can make your data more persistent while having edits displaying immediately. A simple system with front end pages that load the content from the database when the cache is empty (and store it in the cache when it does so) combined with an editor that invalidates it and/or reloads it sounds ideal to me, should you decide to proceed with implementing caching.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top