Apr 14 2009

How To Smarty Cache

Published by Root at 16:47 under Php,smarty

Ok. If you use smarty and some part of your web site are no need to uptime any time, we can use the Smarty cache.

But smarty cache is not usefull for big project. But you can use in very simple let’s start.

First Prepare script for smarty.

require ‘kernel/libs/Smarty.class.php’; // This is my smarty class.

$smarty = new Smarty; //

$smarty->caching = true;
$smarty->cache_dir
= "mycachedir/" where is cache?

if (!$smarty->is_cached(‘myspecial.tpl’)) {
$my_variable=”Hello World”;
$smarty->assign(‘exam_variable’,$my_variable);
}

$smarty->display(“myspecial.tpl”);


Ok. It’s finish. If you want to stop any part of script you can use $smarty->caching = false; for stop cache and restart again.

2 responses so far

2 Responses to “How To Smarty Cache”

  1. lukason 07 Sep 2009 at 13:30

    This is not true, smarty cache is very useful, especially in big projects, since the loading time of big projects tends to be more important. You just need to do a little extra work and delete the cache (or even better, just the cache file of a specific file) after something was updated.
    E.g. you use a funtion delete_cache($id); everytime someone saves an input to edit a page in your cms system.

  2. Rooton 14 Sep 2009 at 10:34

    :D . Yeap you can cache for every PAGE, But i want to cache SQL , smarty can’t. ??? For example zend cache, cache anything. So smarty not for big project. If your web site get more comment or more article you can not cache your page. ;)

Trackback URI | Comments RSS

Leave a Reply