views:

91

answers:

1

We have several sites that are mostly content managed using a sql database backend. these sites are most of the time serving up static information unless users change the content by voting or updating (similar to SO). These sites all have master pages where user specific information is often displayed at the top of each page (also similar to SO).

We want to implement output caching to prevent a db hit to get content from the db every request when 90% of the time it is unchanged from the previous requests other than the user information. What is the best way to do this? I am obviously aware of partial caching through controls but that would mean making each pages content a control, which we do not want to do.

Any suggestions? I assume SO has a caching strategy to achieve this.

A: 

One idea I had a bit ago was to cache the entire page and then, fill in user-spcific information using javascript. It'd require a very large re-architecture most likely, but the gains could be immense.

I wrote a proof of concept about it but the idea is render out the user data dynamically in an iframe:

<html>  
<head>  
<script type="text/javascript">  
var iData = {};
iData.loggedIn = true;  
iData.username = 'Your Username';  
iData.userLevel = 'Mod';  
</script>  
</head>  
</html>  

Then in your (cached, static) page, manipulate the page:

var iData = window.iframe.iData;
if(!iData.loggedIn)
{
    $('topnav_hidden').style.display = 'none';
    $('topnav_pm').style.display = 'none';
    $('topnav_mcp').style.display = 'none';
    $('topnav_logout').style.display = 'none';
    hideModFunctions();

    var replyLinks = getElementsByClass('reply_links', $('mainTable'), 'span');
    for(var i=0;i<replyLinks.length;i++)
        replyLinks[i].style.display = 'none';

    var replyLinks = getElementsByClass('reply_links', $('basicTable'), 'span');
    for(var i=0;i<replyLinks.length;i++)
        replyLinks[i].style.display = 'none';
}
else
{
    $('fillin_username').innerHTML = iData.username;
    $('topnav_register').style.display = 'none';
    $('topnav_login').style.display = 'none';
    if(iData.userLevel != 'Mod' && iData.userLevel != 'Admin')
        hideModFunctions();
}

Now to be clear - this is probably not a practical approach for most people, but if you're really getting hammered and your content is 99% static, this could net you some big gains if you were willing to invest a lot of effort in setting it up.

Tom Ritter
An interesting idea, however could have usability implications as parts of the site would be unusable with no js capability
Sheff