View previous topic :: View next topic |
Author |
Message |
SebastianW Smarty Rookie
Joined: 05 Mar 2015 Posts: 5
|
Posted: Thu Mar 05, 2015 11:54 am Post subject: Cache - diffrent pages. |
|
|
In start of my post I want to say : hello , and sorry for my english.
my code is :
Code: |
function render()
{
global $smarty;
global $cashing;
if (DEVELOPMENT_ENVIRONMENT == false)
{
$smarty->caching = 1;
$smarty->cache_lifetime = 30;
$smarty->compile_check = false;
}
$smarty->display('header.tpl');
if (DEVELOPMENT_ENVIRONMENT == false)
{
$smarty->caching = 0;
$smarty->cache_lifetime = 0;
$smarty->compile_check = true;
}
$smarty->display( 'body.tpl');
if (DEVELOPMENT_ENVIRONMENT == false)
{
$smarty->caching = 1;
$smarty->cache_lifetime = 30;
$smarty->compile_check = false;
}
$smarty->display('footer.tpl');
if (DEVELOPMENT_ENVIRONMENT == false)
{
$smarty->caching = 0;
$smarty->cache_lifetime = 0;
$smarty->compile_check = true;
}
}
|
What I want is :
Header and footer are caching, and refreshing avery 30 second. But now they are caching, but not changing when i was change my .tpl.
body.tpl - never caching.
Is ti possible ?
I supose the problem is : compile_check set tu false.
But I don't want to my page check new version of file each reload page, only after each 30 second - this is not working.
best regards
[/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Mar 05, 2015 6:24 pm Post subject: Re: Cache - diffrent pages. |
|
|
SebastianW wrote: | In start of my post I want to say : hello , and sorry for my english. |
You're welcome.
I see a number of issues with your code.
1. Using globals.
Just drop the function(), you do not need it. Or if you need it, pass globals as parameters.
2. Setting up your code as development environment.
Do the opposite. Set it for production, but enable development options upon request. Will also make your code more readable.
Code: |
if (DEVELOPMENT_ENVIRONMENT)
{
$smarty->caching = Smarty::CACHING_OFF;
$smarty->compile_check = true;
} |
SebastianW wrote: | What I want is :
Header and footer are caching, and refreshing avery 30 second. But now they are caching, but not changing when i was change my .tpl.
body.tpl - never caching.
Is ti possible ? |
Smarty::CACHING_LIFETIME_SAVED and use {nocache} where it is applicable.
And your code will shrink to just 3 lines down from 30.
Quote: | I supose the problem is : compile_check set tu false. |
Compilation have nothing to do with caching.
Two separate processes.
Quote: | But I don't want to my page check new version of file each reload page, only after each 30 second - this is not working. |
You disable compilation entirely on production.
When you redeploy your service/update templates, then you just purge compiled store once new templates are in place. |
|
Back to top |
|
SebastianW Smarty Rookie
Joined: 05 Mar 2015 Posts: 5
|
Posted: Fri Mar 06, 2015 8:21 am Post subject: |
|
|
thx for reply.
Now my code looks like :
Code: |
if (DEVELOPMENT_ENVIRONMENT)
{
$smarty->caching = Smarty::CACHING_OFF;
$smarty->compile_check = true;
}
else
{
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->compile_check = false;
}
$smarty->setCacheLifetime(30);
$smarty->display('header.tpl');
$smarty->setCacheLifetime(3600);
$smarty->display( 'body.tpl');
$smarty->setCacheLifetime(30);
$smarty->display('footer.tpl');
$smarty->setCacheLifetime(3600);
|
My body.tpl starts with{nocache} and finish with {/nocache}.
But it is not working. I change my tpl file and save. Wait 30 second and - nothing change.
header.tpl and body.tpl - i don't see any changes.
Why ?
[/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Mar 06, 2015 8:32 am Post subject: |
|
|
I think you're confusing compilation and caching.
Would be best if you go over and re-read the documentation. |
|
Back to top |
|
SebastianW Smarty Rookie
Joined: 05 Mar 2015 Posts: 5
|
Posted: Fri Mar 06, 2015 8:47 am Post subject: |
|
|
ok.
Tell me one thing - becouse maybe this is my problem.
When ( in production ENVIRONMENT ) body was changing - i always see new version.
When ( in production ENVIRONMENT ) header was changing - i always see new version in 30 second.
When ( in production ENVIRONMENT ) body.tpl was changing ( by me ) - I not see new version becouse this is compilation not caching ?. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Mar 06, 2015 8:53 am Post subject: |
|
|
Yes. Template is HOW your site LOOKS, not what DATA it PRESENT.
Data is what you send to template with Smarty::assign().
Normally, templates on production are compiled once and never changed, unless the site style is changed. |
|
Back to top |
|
SebastianW Smarty Rookie
Joined: 05 Mar 2015 Posts: 5
|
Posted: Fri Mar 06, 2015 8:57 am Post subject: |
|
|
thank you very much.
One more things.
When I want change my .tpl than I must manualy remove all cached files from server ? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Mar 06, 2015 9:08 am Post subject: |
|
|
Not cache. You need to nuke compiled versions of the templates. (The content of Smarty::compile_dir directory.) |
|
Back to top |
|
SebastianW Smarty Rookie
Joined: 05 Mar 2015 Posts: 5
|
Posted: Fri Mar 06, 2015 9:14 am Post subject: |
|
|
Thank you for your interest
Best regards. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 06, 2015 2:10 pm Post subject: |
|
|
If a template called with smarty::display() does not contain subtemplates ({include}) there is no performance difference if $marty->compile_check is true as the source tpl file stats of the main template will be read anyway.
But calling smarty::display() 3 times does affect performance.
I would do the following:
body.tpl: Code: | {include file='header.tpl' cache_lifetime=30}
....
{include file='footer.tpl' cache_lifetime=30} |
The {include ... cache_lifetime=30} will force that include subtemplate will be separately cached.
See http://www.smarty.net/docs/en/language.function.include.tpl
If body.tpl is not cached it does not need {nocache} tags.
Just leave $smarty->caching off and call $smarty->display( 'body.tpl');.
What is the reasion for a cache_lifetime=30 for header.tpl and footer.tpl?
If these templates contain only text (no template variables used) you gain nothing by caching these templates. |
|
Back to top |
|
|