Add on for my life

How To Smarty Cache

by Root on Apr.14, 2009, 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 Comments for this entry

  • lukas

    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.

  • Root

    :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. ;)

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

Archives

All entries, chronologically...