March 2013 - Digital Tool Factory blog March 2013 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to explain caching to clients

'Translator' photo (c) 2010, Mace Ojala - license: http://creativecommons.org/licenses/by-sa/2.0/I recently implemented a quick performance fix on a client’s site recently by implementing caching.  I explain caching with the following metaphor.

Imagine that your site is a book.  A book written in a weird mix of Latin, Sanskrit and Old Norse.    It’s precise,  complicated and requires translation into English by an expert translator before it can be read by the public.

Your web server translates the book.  Anytime, someone tries to read the book they cannot read it directly; they need someone (the web server) to translate the book.  This can take a lot of time and energy for the translator to do, but it has to be done.

 

A simple version of the process

To clarify, the process works like this

  1. Person makes a request, i.e. “what does that book say? [Non Resource Intensive Step]
  2. The translator looks at the book, and makes a careful translation into modern day English of the book from the original Latin, Sanskrit, and Old Norse.    This can take a long time [Resource Intensive Step].
  3. After the translator completes the translation he sends it on it’s way to the person who made the request [Non Resource Intensive Step].
  4. The person who makes the request receives the translation and the interaction is complete [Non Resource Intensive Step].

That all sounds good, but the problem is that the four step process has to happen each and every time anyone makes a request, especially the resource intensive step two.  So, if a web page gets 1000 requests an hour, resource intensive step #2 runs 1000 times.

 

The first request with caching

Now imagine if the translator makes a copy of the English translation after he sends it out the first time.  The first time someone makes a request for a translation the process looks like this.

  1. Person makes a request, i.e. “what does that book say? [Non Resource Intensive Step]
  2. The translator checks to see if there are any photocopies of the translation that are less than an hour old [Non Resource Intensive Step]
  3. The translator looks at the book, and makes a careful translation into modern day English of the book from the original Latin, Sanskrit, and Old Norse.    This can take a long time. [Resource Intensive Step]
  4. After the translator completes the translation he makes photocopies of the translation. [Non Resource Intensive Step]
  5. Then the translator sends the photocopy of the translation on it’s way to the person who made the request. [Non Resource Intensive Step]
  6. The person who makes the request receives the translation and the interaction is complete. [Non Resource Intensive Step]

Subsequent requests with caching

Subsequent requests for the book look like this

  1. Person makes a request, i.e. “what does that book say? [Non Resource Intensive Step]
  2. The translator sends the photocopy of the translation on it’s way to the person who made the request. [Non Resource Intensive Step]
  3. The person who makes the request receives the translation and the interaction is complete. [Non Resource Intensive Step]

The first time someone makes a request the process runs a little slower, but since each subsequent request for the book omits all of the resource intensive steps, the whole process take up much less time and fewer resources, making for a much lower delivery time on average, e.g. for every 1000 requests for a page, resource intensive step #2 runs 1 time, not 999 times.

Making a photocopy is pretty close to caching.  The web server makes a copy of the page it just created and sends it on it’s way to web browsers.

 

What are the downsides of caching?

What are the downsides of caching, and why doesn’t everyone use it?   I’ve seen two main reasons not to use caching.

  1. The contents of the book can change unexpectedly.  If it does, then the translator is handing out old editions of the book.  That might be fine for some sites, but for others it might be catastrophic   For example, if a blog serves up a slightly out of date version of a post no one will care that much, but if a stock market application serves up old stock prices people will care a lot.  With caching, the translation/web page can be up to an hour old.
  2. It makes debugging much harder if everyone sees slightly different versions of the same thing.

That’s how I explain caching to clients.  I’ve always had people find the metaphor clear and easy to understand.


18
Mar 13


Written By Steve French

 

How to install wordpress in a subdirectory of a site with an existing .htaccess file

This happened to me whilst working on a  pre-existing site recently.

 

The Problem

You are trying to install WordPress onto a subdirectory of an existing site that uses the .htaccess files for routing.  When you try to add in the changes needed for WordPress to work you break the existing site.

The Cause

WordPress .htaccess files do not play nicely with other .htaccess files

The Solution

Simply add in the WordPress generated .htaccess files in the WordPress directory, and everything magically works.

For Unix people this must be obvious, but for me it was surprisingly brilliant.

 


13
Mar 13


Written By Steve French

 

The case of the disappearing WordPress widgets

A silly one this time

The Problem

I was recently working on someone else’s WordPress theme that made extensive use of WordPress Widgets and the new dynamic sidebar feature.  I was able to recreate the widgets (there was a working staging site) but the on the production site the widgets did not appear.  What to do about disappearing WordPress widgets?

The Cause

I had changed the name of the theme.  For some reason the register_sidebar has to have the name hard coded, for example

register_sidebar( array(
		'name' => __( 'Banner Area', 'themename' ),
		'id' => 'Banner-area',
		'description' => __( 'Banner area', 'themename' ),
		'before_widget' => ' <div>',
		'after_widget' => '</div>',
		'before_title' => '<div><h1>',
		'after_title' => '</h1></div>',
	) );

The Solution

Just change the name of the theme to the new name and you’re all set!


12
Mar 13


Written By Steve French

 

A simple tip on the Bing Keywords API

Just a quick reminder for anyone who uses the Bing Keywords API.

As you become aware as you do more and more things with the API, the code itself it beautiful, but the access to it is difficult.  I recently (a month or two ago actually)  on tech support finding out that the developer token (given to you in the introductory email) is the same as the access key (which they reference numerous times in the training material.  They are one and the same.


11
Mar 13


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.