Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Cache in version 2.6.26

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
zebu
Smarty n00b


Joined: 28 Jan 2011
Posts: 4

PostPosted: Fri Jan 28, 2011 8:39 am    Post subject: Cache in version 2.6.26 Reply with quote

Hi,

I have problem width caching, below is my simple code

//Some code php and crate smarty object
if(!$smarty->is_cached('index.tpl'))
{
//Some php code is run when smarty cache is off
}
else
{
//When cache is on I display cache index.tpl
$smarty->display('index.tpl');
}

All time function is_cached return false and I check why and I find:

function smarty_core_read_cache_file in core.read_cache_file.php line 56 is:

if($smarty->caching == 2 && isset($_cache_info['expires'])){

This if return true but if I check $smarty->caching is 1 and $_cache_info['expires'] isset. If we have fasle && true = false

If I change if(!$smarty->is_cached('index.tpl')) on if($smarty->is_cached('index.tpl')) I don't get any cache file ;/

Sombady can help me?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Jan 28, 2011 4:04 pm    Post subject: Reply with quote

You need to call display() outside the condition, otherwise a cache file will never be created.

Code:
if(!$smarty->is_cached('index.tpl'))
{
  //Some php code is run when smarty cache is off
}
$smarty->display('index.tpl');
Back to top
View user's profile Send private message
zebu
Smarty n00b


Joined: 28 Jan 2011
Posts: 4

PostPosted: Sat Jan 29, 2011 12:18 pm    Post subject: Reply with quote

It's the same. Before start the page I check the cache folder is empty then I reload the page. I check the cache folder and I founded index.tpl cache like %%93^934^9345875E%%index.tpl After then I realod page once more and the $smarty->is_cached('index.tpl') return falshe why ?

I readed all this forum and all documentation but I don't know what I do wrong ;/

Code:
//Some code php and crate smarty object
if(!$smarty->is_cached('index.tpl'))
{
//Some php code is run when smarty cache is off
$smarty->display('templates/index.tpl');
}
else
{
//When cache is on I display cache index.tpl
$smarty->display('index.tpl');
}
$smarty->display('index.tpl');
Back to top
View user's profile Send private message
TakingSides
Smarty Rookie


Joined: 11 Dec 2010
Posts: 30

PostPosted: Sat Jan 29, 2011 12:57 pm    Post subject: Reply with quote

Well i can spot a little difference in your code..

Literally like U.Tews has said.
Code:
if(!$smarty->is_cached('index.tpl'))
{
//Some php code is run when smarty cache is off
}

$smarty->display('index.tpl');



However your code is slightly inconsistent. When no cache you do the following

Code:
if(!$smarty->is_cached('index.tpl'))
{
//Some php code is run when smarty cache is off
$smarty->display('templates/index.tpl');
}


So, why when there is a cache does your template change directory?

Code:
else
{
//When cache is on I display cache index.tpl
$smarty->display('index.tpl');
}


And after this if statement, you do not need to re-display the template for a second time. So it should be.

Code:


// check for a cache file.
i f(!$smarty->is_cached('index.tpl')) {
  //Some php code is run when smarty cache is off
}

// no ELSE needed as, when a cache exists, it'll automatically display that...

// is this correct?
$smarty->display('templates/index.tpl'); // or should it be... $smarty->display('index.tpl'); ?
Back to top
View user's profile Send private message
zebu
Smarty n00b


Joined: 28 Jan 2011
Posts: 4

PostPosted: Mon Jan 31, 2011 2:22 pm    Post subject: Reply with quote

TakingSides thx is ok!

I have 2 questions

1. I want do the same for subtemplates. I have index.php where


Code:
// check for a cache file.
if(!$smarty->is_cached('index.tpl')) {
  //Some php code is run when smarty cache is off
  //Here I include php file which include subtemplates
}
$smarty->display('index.tpl'); ?


and the sub php file look like:
Code:

i f(!$smarty->is_cached('article_entry.tpl',$key)) {
  //Some php code is run when smarty cache is off
}
$smarty->display('article_entry.tpl',$key); ?


but I have my article.tpl file in articles folder for example: templates/articles/article_entry.tpl

And my question is where I should put sub folder articles ?

My second question is. In database I have 200. 000 products and I want cache all of them. If I put 200. 000 file to cache and I load this it will be fast ?
Back to top
View user's profile Send private message
zebu
Smarty n00b


Joined: 28 Jan 2011
Posts: 4

PostPosted: Wed Feb 02, 2011 1:47 pm    Post subject: Reply with quote

Somebady can help me ? ;/
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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