views:

78

answers:

2

I've read lots of material on how to do ASP.Net caching but little on the optimal duration that pages should be cached for.

Let's say that I have a popular site with 50,000 pages. The content does not change frequently, so I could cache pages for up to an hour if I wanted. The server has 16 GB of RAM, but database connections are limited.

How long should pages be cached for?

My thinking is that if I set the cache duration too high (let's say 60 minutes), I will fill up memory with a fraction of the total content, which will continually be shuffled in and out of memory.

Furthermore, let's say that 10% of the pages are responsible for 90% of traffic. If the popular pages are hit every second, and the unpopular ones every hour, then a 60 second cache would only keep the load-intensive content cached without sacrificing freshness.

Should numerous but rarely-accessed content be cached at all?

A: 

One option would be to utilize some sort of disk caching, rather than memory caching, at least for infrequently visited pages. But in general, the point of caching is to support a request that is likely to be made again in a short time. So I would certainly give preference to the frequently requested pages.

joelt
+2  A: 

I don't think you'll ever find a published formula or strict guideline on optimizing your cache. Every situation is going to be radically different, and even from the number of variables you're talking about here, it's impossibly to quantify.

It'll be a combination of experience, guessing, monitoring and incremental adjustments to find your caching sweet spot for any given application.

It sounds like you've already got a handle on what might happen, so I would start with caching the 10% that represent your high traffic, and optimize from there. You may or may not find any performance gains further down the road with your less-used content, but put your effort into the major optimizations first.

womp