View previous topic :: View next topic |
Author |
Message |
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Mon Apr 08, 2013 2:56 pm Post subject: isCached method returning empty result |
|
|
i am using smarty file cache with various cache_id, but isCached method is always returning empty result:
Code: |
$smarty->setCacheDir('/www/doc/www.myserver.com/www/smarty/cache');
$cache_id = md5($_SERVER['REQUEST_URI']);
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(1209600);
if($smarty->isCached('/www/doc/www.myserver.com/www/graphic/smarty/index.tpl', $cache_id)) {
$html = $smarty->fetch("/www/doc/www.myserver.com/www/graphic/smarty/index.tpl", $cache_id);
echo str_replace("<span id=\"cache\"></span>", "from cache", $html);
}
else {
//do some DB stuff here and smarty vars assignation
$smarty->display("/www/doc/www.myserver.com/www/graphic/smarty/index.tpl", $cache_id);
}
|
I can see that smarty is using file cache, but if condition is always false... I was trying to figure it myself, but with no success. please help |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 08, 2013 4:18 pm Post subject: |
|
|
Your code lokks correct. It should return $smarty->isCached(...) true for same compile_id's. |
|
Back to top |
|
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Mon Apr 08, 2013 4:53 pm Post subject: |
|
|
well template is successfully created in smarty_internal_templatebase.php, but it looks that, $template->cached->valid is set, but empty string... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 08, 2013 5:32 pm Post subject: |
|
|
If you look manually in the created cache file, do you see content there? |
|
Back to top |
|
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Thu Apr 11, 2013 8:28 am Post subject: |
|
|
Yes, there is a content in cache file. I decided to post whole code. Maybe i am missing something:
Code: | require('libs2/Smarty.class.php');
$smarty = new Smarty;
$smarty->setTemplateDir('/www/doc/www.myserver.com/www/smarty/templates');
$smarty->setCompileDir('/www/doc/www.myserver.com/www/smarty/templates_c');
$smarty->setCacheDir('/www/doc/www.myserver.com/www/smarty/cache');
$smarty->setConfigDir('/www/doc/www.myserver.com/www/smarty/configs');
$cache_id = md5($_SERVER['REQUEST_URI']);
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(1209600);
if($smarty->isCached('/www/doc/www.myserver.com/www/graphic/smarty/index.tpl', $cache_id)) {
$html = $smarty->fetch("/www/doc/www.myserver.com/www/graphic/smarty/index.tpl", $cache_id);
echo str_replace("<span id=\"cache\"></span>", "from cache", $html);
}
else {
//do some DB stuff here and smarty assignation
$smarty->display("/www/doc/www.myserver.com/www/graphic/smarty/index.tpl", $cache_id);
} |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 11, 2013 3:07 pm Post subject: |
|
|
Why are you using a directory different than your template_dir?
/www/doc/www.myserver.com/www/smarty/templates
vs
/www/doc/www.myserver.com/www/graphic/smarty/
You should set your template_dir, then use paths relative to that in fetch() and display() |
|
Back to top |
|
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Thu Apr 11, 2013 3:39 pm Post subject: |
|
|
well i also tried to set template directory to /www/doc/www.myserver.com/www/graphic/smarty/ and then used relative paths, but smarty wasn't possible to locate my template:
Code: | $smarty->setTemplateDir('/www/doc/www.myserver.com/www/graphic/smarty');
$smarty->fetch("index.tpl", $cache_id); |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 11, 2013 3:49 pm Post subject: |
|
|
run the install test after you setup your directories.
$smarty->testInstall();
Last edited by mohrt on Thu Apr 11, 2013 3:55 pm; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Apr 11, 2013 3:54 pm Post subject: |
|
|
This is strange...
Call $smarty->testInstall(); after you did set all directories. It should show if there are any access/permission problems. |
|
Back to top |
|
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Mon Apr 22, 2013 8:03 pm Post subject: |
|
|
ok, sorry for the delayed response i was on a business trip. This is testInstall output: Code: | Smarty Installation test...
Testing template directory...
/www/doc/www.myserver.com/www/graphic/smarty is OK.
Testing compile directory...
/www/doc/www.myserver.com/www/smarty/templates_c is OK.
Testing plugins directory...
/www/doc/www.myserver.com/www/companies/libs2/plugins is OK.
Testing cache directory...
/www/doc/www.myserver.com/www/smarty/cache is OK.
Testing configs directory...
/www/doc/www.myserver.com/www/smarty/configs is OK.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete. | Everything seems to be okay but isCached method is still returning empty result. I am desperate. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Apr 28, 2013 6:48 pm Post subject: |
|
|
Are there any files in your cache dir? |
|
Back to top |
|
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Sun Apr 28, 2013 7:58 pm Post subject: |
|
|
well i am using memcache now. But when i switch to standard file cache - yes there is a non-empty files in my cache directory. But method is not working... but i must emphasize that i didn't make any changes to original file of newest stable smarty version... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Apr 28, 2013 8:21 pm Post subject: |
|
|
Quote: | Everything seems to be okay but isCached method is still returning empty result |
Not that isCached does not return content. It returns just true/false to indicate if the cache file is valid or not.
You must still call display() or fetch() to get the content. |
|
Back to top |
|
demo055 Smarty Rookie
Joined: 08 Apr 2013 Posts: 12
|
Posted: Sun Apr 28, 2013 8:30 pm Post subject: |
|
|
Quote: | Not that isCached does not return content. It returns just true/false to indicate if the cache file is valid or not.
You must still call display() or fetch() to get the content. |
I know that. I just don't want to call DB stuff, when page is cached. It should return true or false, but it is returning empty string. When i pass the result to PHP "empty" function it returns true.
So isCached returns neither true nor false, just empty string. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Apr 28, 2013 9:52 pm Post subject: |
|
|
isCached() can't return an empty string. It will always return an boolean.
I have verified the code and it does work in thousand's of application.
That's really strange. Which veerion of Smarty do you use? |
|
Back to top |
|
|