• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URGENT: I need to turn off Smarty caching

#1
[eluser]CodeIgniterNewbie[/eluser]
Sorry for the re-post, but I really need to solve this issue quickly:

Per Google: “In general, HTML is not static, and shouldn’t be considered cacheable.” (http://code.google.com/speed/page-speed/...ching.html)

Per Smarty: “....if you are displaying the front page of your website that does not change its content very often, it might work well to cache this page for an hour or more. On the other hand, if you are displaying a page with a timetable containing new information by the minute, it would not make sense to cache this page.” (http://www.smarty.net/manual/en/caching.php)

Since most of my site is dynamic, I decided to turn off Smarty caching. When I looked at Smarty.class.php, line 160, I saw this:

Code:
var $caching         =  0;

I’m sure that there is Smarty caching taking place on my site.

1. How do I turn off Smarty caching?
2. Am I right to want to turn off Smarty caching?
3. Can I do partial caching with Smarty (e.g. my footer TPL is probably not going to change often)

Thanks.

#2
[eluser]jayrulez[/eluser]
doesn't that
Code:
var $caching = 0;
mean that caching is turned off in smarty? What makes you sure that smarty is caching your pages?

#3
[eluser]CodeIgniterNewbie[/eluser]
Yes, that does mean caching is turned off in Smarty. However, I see cache files getting generated in Smarty's cache directory.

I'm trying to turn off Smarty caching because my users are seeing old data on some of my dynamic pages.

#4
[eluser]jayrulez[/eluser]
do you mean the templates_c dir?

#5
[eluser]Thorpe Obazee[/eluser]
Shouldn't you be asking in the Smarty forums?

#6
[eluser]CodeIgniterNewbie[/eluser]
I have. No response. Also, since this is integrated in CI, I thought I would ask here, too.

#7
[eluser]CodeIgniterNewbie[/eluser]
@jayrulez

Smarty defines the cache_dir as "cache." The cache files are appearing there. Also, I have modified the "view" function in MySmarty class:

Code:
echo('The value of caching is: ' . $this->caching . '<br/>');
echo('The value of cache_dir is: ' . $this->cache_dir . '<br/>');            
return parent::display($resource_name);

It's echoing "0" and "cache." I am convinced Smarty cache is turned off, but the cache_dir is getting filled with cache files.

#8
[eluser]jayrulez[/eluser]
download another copy of smarty and use it without modifying it and see if that happens. programming is giving the machine instructions so it shouldn't do something u didn't tell it to do

#9
[eluser]Phil Sturgeon[/eluser]
You don't want to turn off caching everywhere. I would not agree with Google on this one at all. HTML is generated from PHP based on the provided data and conditions. If the data and conditions do not change often, the HTML does not change often.

If you are handling crucial financial data that changes every 2 minutes and contains stock prices or something, then yes, caching is a bad way to go. If you are showing news articles on a high-traffic blog then I'd be tempted to throw that cache up to 30-60 minutes!

Anyway, how you approach this depends on how you have integrated Smarty. You are probably doing something like this:

Code:
$smarty = new Smarty();

// or

$this->load->library('smarty');

To turn off caching you would do this:

Code:
$smarty->caching = 0;

// or

$this->smarty->caching = 0;

You can turn it off on a per-page or per-method basis. Or by calling this multiple times within a method (between the various smarty includes) you can do partial caching which is probably more useful.

Remember: Smarty will use the _c folders for cache AND compile (unless told to do otherwise). The compiled files are not cached and even though they exist and will exist for a while, they are not used as cached content. It is simply how Smarty does its thing.

The difference: .tpl.php = compiled, .tpl = cached


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.