| View previous topic :: View next topic |
| Author |
Message |
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Sun Apr 08, 2012 10:29 am Post subject: lifetime not used? |
|
|
I'm using Smarty 3.1.8 and set the following parameters to enable caching:
| Code: |
$smarty->force_compile = false;
$smarty->compile_check = false;
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(14400);
|
caching is working fine, but I noticed that my generated cache files under the smarty/cache directory contain the following header info:
| Code: |
'cache_lifetime' => 3600,
|
so what is wrong? why do my generated cache files contain a different cache lifetime that the one I've set? |
|
| Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Sun Apr 08, 2012 10:59 am Post subject: |
|
|
just for reference, I've setup my site as follows:
| Code: |
// init smarty here
$smarty = new Smarty();
...
...
$smarty->force_compile = false;
$smarty->compile_check = false;
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(14400);
// prepare to load requested page
$_action = "page".$_GET['page'];
// load page content
if(!$smarty->isCached("template.html", $_action)) {
// load page from DB is not cached
$page = load($_GET['page']);
// Store data into Smarty template
$smarty->assignByRef('PAGECONTENT', $page);
}
// load content template
$smarty->assign('TEMPLATE', "page.html");
// load and display complete template
$smarty->display('template.html', $_action);
|
template.html contains the following line:
<div id="page">{include file="$TEMPLATE"}</div>
which in turn loads the page content from the $TEMPLATE (page.html in this case)
page.html contains the following line:
<div id="content">{include file="$PAGECONTENT"}</div> |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4183 Location: Hamburg / Germany
|
Posted: Sun Apr 08, 2012 12:18 pm Post subject: |
|
|
| Note that after you have changed your cache_lifetime existing cache files will get the new time only when their old life time has expired. |
|
| Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Sun Apr 08, 2012 12:38 pm Post subject: |
|
|
| I only set the lifetime once, there is no "old" or "new". |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4183 Location: Hamburg / Germany
|
Posted: Sun Apr 08, 2012 6:11 pm Post subject: |
|
|
The cache file must have been created with a cache lifetime of 3600.
If you modify the value in your script you will see it in the cache file only if the old life time has expired and the cache file was renewed. |
|
| Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Sun Apr 08, 2012 10:12 pm Post subject: |
|
|
Am I talking in a foreign language? it seems like nobody understands what I said.
---------------------------------------------------------------
THERE IS NO 3600 LIFETIME ANYWHERE IN MY SCRIPT
--------------------------------------------------------------- |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Sun Apr 08, 2012 10:17 pm Post subject: |
|
|
| CrazyTemplate wrote: | Am I talking in a foreign language? it seems like nobody understands what I said.
---------------------------------------------------------------
THERE IS NO 3600 LIFETIME ANYWHERE IN MY SCRIPT
--------------------------------------------------------------- |
clear all of your cache files, reload the pages. look at the cache files again. do they still say 3600? I think Uwe is under the impression you changed the lifetime at a later date, after cache files had been generated with the default lifetime. |
|
| Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Sun Apr 08, 2012 10:25 pm Post subject: |
|
|
Of course I've cleared the entire cache, even made sure the directories cache and template_c where both completely empty.
No matter what I do, the cache files always contain the lifetime 3600, as if the $smarty->setCacheLifetime(14400); function is not there.
I tried to switch between Smarty::CACHING_LIFETIME_SAVED and Smarty::CACHING_LIFETIME_CURRENT as well.
I also change the order of calling the functions, like:
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(14400);
and
$smarty->setCacheLifetime(14400);
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
but nothing made a difference, all my cache files are generated with 3600 lifetime in them. |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4183 Location: Hamburg / Germany
|
Posted: Mon Apr 09, 2012 10:50 am Post subject: |
|
|
Can you add a
var_dump($smarty);
just before the isCached() call and look for the value of the $cache_lifetime property.
The value for the cache file is copied from there.
I have no explaination for the behaviour at your place.
It does work in all tests.... |
|
| Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Mon Apr 09, 2012 2:59 pm Post subject: |
|
|
var_dump gives me the following:
["cache_lifetime"]=>
int(14400)
but the cache file still has:
'cache_lifetime' => 3600, |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4183 Location: Hamburg / Germany
|
Posted: Mon Apr 09, 2012 3:52 pm Post subject: |
|
|
This is really strange.
A value of 3600 is used only as default value of cache_lifetime, which is replaced by your custom value of 14400 as your var_dump() shows.
Is there any other usage of the $smarty object after $smarty = new Smarty(); and before you set the cache lifetime?
Run the demo in the demo folder (index.php) ; Does it show same behaviour? |
|
| Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 13
|
Posted: Mon Apr 09, 2012 4:07 pm Post subject: |
|
|
Right now I'm testing the various {insert} blocks and the smarty plugins that we are using, one by one, to see if something tries to set the lifetime again.
I haven't found anything so far, and even a simple grep can't find anything that has 3600 in it. |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4183 Location: Hamburg / Germany
|
Posted: Mon Apr 09, 2012 4:22 pm Post subject: |
|
|
Do you create somewhere in the plugins or inserts another instance of the Smarty object?
Could there be another call of template.html at another place as the main script? |
|
| Back to top |
|
|