Benjamin Tinker Team : Web Development

Just Cache it!

Benjamin Tinker Team : Web Development

When developing high content driven sites that need to respond in the fastest possible manner it is a good idea to have some kind of caching policy that can reuse as much of your content as possible. By taking a small hit for initial load times you will save a lot of time for successive loads of content on your site. If there is any one control on your page that does not change at every page load then there is a good place to put some caching on it. Here are my top 5 guidelines when determining if caching is a good idea.

  1. Is it static content? Content such as About Us, Contact Us, Terms and Conditions pages and any content that you know is not going to change on a daily basis. Always cache this.
  2. Is it content that does change but not every hour but does on occasion? If you are selling products on your website and need to maintain summaries of some information but need to actively maintain pricing and stock levels  then some selective cache controls is a good idea. You don’t have to cache an entire page but can use the .NET framework to build cache controls for selective data on your site.
  3. Images, CSS and Javascript? You know you have to cache them. IIS has some settings that allow you cache all static content on your site. This  usually includes your CSS, Javascript and Images. Adding the  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />  line of code to your web.config will automatically cache static content for 7 days. A good time saver.
  4. Site configuration settings? With modern CMS setups chances are you are going to have some settings such as contact email addresses, phone numbers, pagination controls or anything that gets used over and over for common functions on the site. If you set up a new Settings class that is loaded into memory when the site starts you can gather this information faster without needing to call the database each time.
  5. If it’s not being updated by the site and/or administration every 24 hours and I mean EVERY 24 hours then cache it. You can set your default cache time out to 12 hours to ensure it clears at a reasonable time for updates to come through.

Overall there are many tips and trick to increase the load time of your site such as cache controls on the server, data caching in SQL, Umbracos built in caching and the built in IIS cache controls. Using these brings your site to the client much faster and then faster for the next person to see the same page which is something every user wants to see. But, remember to build in your ‘Clear Cache’ controls too so should the client require something to update before the timeout occurs they can click a button and do so. Prior preparation with this gets their site running faster and keeps you out of their server having to restart it every time they want content published.