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

Smarty Database Cache

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
eljakim
Smarty n00b


Joined: 25 Jan 2022
Posts: 1

PostPosted: Tue Jan 25, 2022 7:06 am    Post subject: Smarty Database Cache Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jan 28, 2022 10:46 am    Post subject: Reply with quote

Replied on reddit. Sorry I got overwhelmed by the events.
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 -> Smarty 3 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