Memcache and Smarty
mmagpayo at purevideo.com
Mon Sep 10 08:29:00 UTC 2007
We actually use this combination. What we do is cache the data from our
DB calls (usually in an array form) in memcache. We'll use that data as
input to our Smarty templates (making checks to see if our data is
already in memcache or if we need to hit the DB and repopulate). Then
we'll cache the Smarty templates as well, but we do it selectively as
there are certain pages that need to be fairly dynamic.
The hardest part is finding appropriate cache times at each level. What
seems to work well for us is to cache Smarty for a shorter time than
what is being stored in memcache. The difficult part is adjusting both
to match how dynamic the page is. Also, depending on how often your
data changes, you really have to keep track of when to clear caches and
also build a mechanism to do so (both memcache and Smarty caches).
My advice is to start with caching turned off in Smarty and to store
Smarty input on memcache. Use Smarty strictly for displaying first
before diving into using it to cache. Then adjust from there. Keep an
eye on your data and you'll get an idea of how to adjust properly.
> So you're basically saying, cache the output right before sending it
> to Smarty, and not cache the end html result. Is that right?
On 9/10/07, Brian P Brooks <Brian.Brooks at colorado.edu> wrote:
> You must have a PHP file that calls the smarty engine. In that file
> assign variables to Smarty. Do you caching from that file, and then
> the cached contents to Smarty's engine via something like
> Brian Brooks
> brian.brooks at colorado.edu
> Mobile: 303.319.8663
> On Sep 10, 2007, at 12:24 AM, J A wrote:
> I've read that it's not good to use Memcache to cache MySQL queries,
> MySQL buffer already does this. Instead, I should cache the html
> Is this what one should always do?
> I'm running PHP and using Smarty for templates. The PHP throws the
> to Smarty, and Smarty is the thing that outputs the html. Thus my
> application is not able to grab the html output. Or is there a way to
> For instance, in a page I might have a "about us" section, a "friends
> and a "blog list". I'd like to cache each of those sections.
memcached mailing list
memcached at lists.danga.com
End of memcached Digest, Vol 38, Issue 16
More information about the memcached