What to cache?

Rob Sharp rob.sharp at thesoundalliance.net
Mon Jul 30 05:00:08 UTC 2007


On Mon, 2007-07-30 at 12:43 +0800, K J wrote:
> Using an engine such as Smarty (smarty.php.net) gives you more
> granular control of caching page elements, but I'm not exactly sure
> what you want to cache.
>         I'm looking to cache things like, "recently logged in
>         members", or "latest blog posts".  Would it be best to use
>         Smarty for this? Or Memcache?  With Memcache, all web servers
>         will be able to obtain the same data, whereas with Smarty,
>         each web server would have to cache its own. 

Smarty provides you with a mechanism to cache HTML templates, the
default method being to file. This guy has a memcached backend for
Smarty: http://swag.dk/swag/kode/

If you're gonna cache data in memcache and handle the page build and
rendering yourself, you don't need Smarty.

> Often SQL query caching isn't hugely beneficial as your database
> server most likely caches pretty well. Caching HTML portions to reduce
> database queries will most likely give you a huge performance benefit.
>         I'm not understanding you here. Do you mean, it can speed
>         things up a lot if I cache the end result HTML portion in
>         Memcache?

You can cache HTML fragments in memcache, or you can cache the data that
you need to build those fragments in memcache. What works best depends
on your setup. YMMV!

Rob.


>  
> On 7/30/07, Rob Sharp <rob.sharp at thesoundalliance.net> wrote:
>         On Mon, 2007-07-30 at 11:44 +0800, K J wrote:
>         
>         > There are portions of my PHP application that updates every
>         > 5 minutes or so.  Thus I think it's a great candidate for
>         > caching, as opposed to having the server refresh that
>         > portion every time there's a query.
>         
>         Yes, there's huge benefits to be gained from it.
>         
>         > 
>         > As far as I'm aware, there isn't a PHP partial page caching
>         > available is there?  
>         
>         Using an engine such as Smarty (smarty.php.net) gives you more
>         granular control of caching page elements, but I'm not exactly
>         sure what you want to cache.
>         
>         > 
>         > So, I'm thinking of using Memcache instead.  Now, I can
>         > cache the SQL queries, or I can cach that portion of the
>         > page (with html rendered).  However, if caching that
>         > portion, it would mean more internal LAN traffic for every
>         > page view request.
>         
>         Often SQL query caching isn't hugely beneficial as your
>         database server most likely caches pretty well. Caching HTML
>         portions to reduce database queries will most likely give you
>         a huge performance benefit. 
>         
>         Do you currently have issues with LAN traffic that make you
>         think using memcache will be a problem? You need to move a lot
>         of data around to saturate a gigbit switch.
>         
>         You may also consider a sole memcache instance per web server,
>         whereby traffic would not leave the server, which may help if
>         you have network saturation issues. 
>         
>         Thanks,
>         Rob.
>         
>         Rob Sharp
>         Development Lead 
>         
>         telephone: 02 9282 4049
>         facsimile: 02 9282 4099
>         skype: qu4nnum
>         
>         
>         
>         
>         Sound Alliance 
>         inthemix : FasterLouder : Thought By Them : SameSame 
>         
>         
>         100% recycled electrons were used for the composition of this
>         email 
>         - please don't print it unless you need to! 
> 
> 

Rob Sharp
Development Lead 

telephone: 02 9282 4049
facsimile: 02 9282 4099
skype: qu4nnum



Sound Alliance 
inthemix : FasterLouder : Thought By Them : SameSame

"Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them." -- Syndicate Wars

100% recycled electrons were used for the composition of this email 
- please don't print it unless you need to!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070730/914d904e/attachment-0001.html


More information about the memcached mailing list