|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
eljakim Smarty n00b
Joined: 25 Jan 2022 Posts: 1
|
Posted: Tue Jan 25, 2022 7:06 am Post subject: Smarty Database Cache |
|
|
Hi guys,
I'm happily using Smarty. One thing I just noticed is that while the caching templates from the database works just fine, Smarty always makes one request to the database. Even though I don't think it should.
This is what I do to initialise:
Code: |
$smarty->registerResource("db", new Smarty_Resource_DB());
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCompileCheck(false);
$smarty->setCacheLifetime(-1);
|
This is my resource implementation:
Code: |
class Smarty_Resource_DB extends Smarty_Resource_Custom {
protected function fetch($name, &$source, &$mtime) {
error_log('Fetch: '. $name);
$template = new Tbltemplate();
$template->tpl_template_key = $name;
if (!$template->find()) {
$source = null;
return;
}
$template->fetch();
$source = $template->tpl_content;
$mtime = time();
return;
}
}
|
Whenever I want to clear the cache I just delete my cache/compile directories, which works great.
Every page request shows in my database log that one query is sent. (I also see that 'Fetch:' appear in my error_log. But, the result is obviously not used, since I see on the frontend that only the cached version is used.
Is there a way to disable to call to fetch() ? I only want that to happen if it cannot find a cached version on disk. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jan 28, 2022 10:46 am Post subject: |
|
|
Replied on reddit. Sorry I got overwhelmed by the events. |
|
Back to top |
|
|
|
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
|