Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

when does Smarty cache rebuild a page?

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Fri Oct 15, 2004 12:36 am    Post subject: when does Smarty cache rebuild a page? Reply with quote

I'd like to force Smarty to rebuild cached pages at scheduled times (instead of waiting for the ttl to expire). I tried using a cron job to touch the cache files and set the last-modified time older than the ttl. I also tried touching the template files to try to fool Smarty into thinking the template files changed. Neither works.

But when I upload a new template file, Smarty knows to rebuild the cache file. And somehow Smarty determines the ttl has expired.

So how does Smarty know when to rebuild a cache file? The mechansim doesn't seem to be effected by the last-modified time of the cache file or template file.
Back to top
View user's profile Send private message AIM Address
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Oct 15, 2004 7:58 am    Post subject: Reply with quote

to force a rebuild just remove the cachefile.

the ttl and the dependend templates are stored in some kind of header inside the cachefile.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Fri Oct 15, 2004 5:00 pm    Post subject: Reply with quote

messju wrote:
to force a rebuild just remove the cachefile.


Yes, but when I do a remove of the cache file I get an error message displaying on the first request for the page. It's not something I want visitors to see. Can I surpress the error message on a per-page basis (without turing off display of all error messages for other php pages?).

Exception message: fopen(/var/php/smarty/www. mysite.com/cache//%%934^%%934377282^index.tpl.html): failed to open stream: No such file or directory
Error code: 2
-- Backtrace --
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/Smarty.class.php(1728): fopen
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/core/core.read_cache_file.php(43): smarty_formsess._read_file
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/Smarty.class.php(1012): smarty_core_read_cache_file
/home/.sites/93/site37/web/index.php(23): smarty_formsess.is_cached

Exception message: fopen(/var/php/smarty/www.mysite.com/cache//%%934^%%934377282^index.tpl.html): failed to open stream: No such file or directory
Error code: 2
-- Backtrace --
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/Smarty.class.php(1728): fopen
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/core/core.read_cache_file.php(43): smarty_formsess._read_file
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/Smarty.class.php(1183): smarty_core_read_cache_file
/home/.sites/93/site37/web/crossbar/lib/smarty/libs/Smarty.class.php(1115): smarty_formsess.fetch
/home/.sites/93/site37/web/index.php(60): smarty_formsess.display
Back to top
View user's profile Send private message AIM Address
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Oct 15, 2004 5:54 pm    Post subject: Reply with quote

I don't see errors when I remove cache files, do you have NFS in the mix, or some sort of file caching?

If compile_check is on, when you touch your template files they should get recompiled even with caching enabled.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Oct 15, 2004 7:49 pm    Post subject: Reply with quote

Perhaps it is a concurrency issue between access users and the cleanup process? Or a wonky PHP accelerator of some sort?

It may be useful if his removal script also recreated the appropriate cache images via a force_recompile.

FWIW, I suspect that the pseudo-header is used (look at the first couple of lines of a cache file to see it) because mtime and atime are not always available on all file systems.
Back to top
View user's profile Send private message
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Fri Oct 15, 2004 7:55 pm    Post subject: Reply with quote

mohrt wrote:
If compile_check is on, when you touch your template files they should get recompiled even with caching enabled.


Thank you! That's the tip I needed. I've just added
$smarty->compile_check = true;
and will see what happens at 5pm after the templates are touched.

You guys are great!
Back to top
View user's profile Send private message AIM Address
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Fri Oct 15, 2004 8:00 pm    Post subject: Reply with quote

mohrt wrote:
I don't see errors when I remove cache files, do you have NFS in the mix, or some sort of file caching?.


Regarding the error message, there's no NFS here, just serving files from the file system (Linux on a RAQ550). The Zend Optimizer v2.5.2 is in use but I don't think it impacts the issue. Is there something in the phpinfo() that would help to know?
Back to top
View user's profile Send private message AIM Address
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Oct 15, 2004 8:11 pm    Post subject: Reply with quote

there's an @fopen that issues an error if your error-handler doesn't honor the fact that the @ should supress any possible error messages.

what version of smarty do you use? more recent ones prevent a triggering by a prior file_exist-check.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Fri Oct 15, 2004 8:29 pm    Post subject: Reply with quote

messju wrote:
what version of smarty do you use? more recent ones prevent a triggering by a prior file_exist-check.


I'm using Smarty 2.6.0.
Back to top
View user's profile Send private message AIM Address
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Oct 15, 2004 9:21 pm    Post subject: Reply with quote

make your error-handler be silent on silenced expressions via php's @-operator.

or maybe upgrade to 2.6.6 and see if the problem persists.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Sat Oct 16, 2004 1:26 am    Post subject: Reply with quote

fortuity wrote:
I've just added
$smarty->compile_check = true;
and will see what happens at 5pm after the templates are touched.


It's 5pm and everything worked perfectly. Thanks for the tip about using compile_check, it makes an easy solution. My cron job touches the template files at 5pm, Smarty thinks they changed, and with "compile_check = true", the cache files get regenerated. Now, every day at 5pm, the cache regenerates, even if we haven't reached the full ttl. Lovely!
Back to top
View user's profile Send private message AIM Address
fortuity
Smarty Rookie


Joined: 23 Dec 2003
Posts: 20
Location: Marin County, California

PostPosted: Sat Oct 16, 2004 1:45 am    Post subject: Reply with quote

messju wrote:
maybe upgrade to 2.6.6 and see if the problem persists


I tried an upgrade to 2.6.6 and had to backout in a hurry, because I'm getting an error trying to use an include file that I use on dozens of pages.
Exception message: Smarty error: unable to read resource: "header.tpl.html"

I successfully used
{include file="header.tpl.html"}
in Smarty 2.6.0 and 2.6.2
but now with 2.6.6 I've got to specify the full path to get it to work:
{include file="/home/sites/www.mysite.com/web/header.tpl.html"}

What changed and can I configure to get the old behaviour?

I'll start digging around the docs, I'm sure this has been asked already.
Back to top
View user's profile Send private message AIM Address
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Oct 16, 2004 5:14 pm    Post subject: Reply with quote

of course you have to test such things in a testing environment before you roll it out on a production system.

2.6.0 used php's include_path to search for templates if it doesn't find it in template_dir. 2.6.6 doesn't do that anymore.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP