Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:49:42+00:00 2026-05-26T05:49:42+00:00

I am going to build a site that have dynamic content (properties as title,

  • 0

I am going to build a site that have dynamic content (properties as title, url, etc) in the database. I guess it would be very unneccerary to query everything out and assign the variables, everytime, so I’ve read about caching.

I use Smarty template, system.

   include('libs/Smarty/Smarty.class.php');

    $smarty = new Smarty;
    $smarty->setCaching(true);

    if (!$smarty->isCached('index.tpl')) {

    //query here and assign..
    $smarty->assign('title', 'Test');
    }

    $smarty->display('themes/simple/index.tpl');
  1. The code above When does it recheck the cache? If I do a change in my database site properties, I want INSTANTLY change upon my site, can be very important stuff like put the site to maintenance, etc.
  2. Do I really need to query all data, again and again on every page load to grab the site info, or is there any solution, like checking the database row structure with the cache, or something like that?

Solutions, I need!


UPDATE:
I try the method of clearCache, but it doesn’t seem to work properly. I update the database, but the “clearCache” method, doesn’t seem to be triggered, or something.

$smarty = new Smarty;
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);

//just to test
$smarty->clearCache('index.tpl');


if (!$smarty->isCached('index.tpl')) {



//do stuff here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:49:42+00:00Added an answer on May 26, 2026 at 5:49 am

    When modifying stuff in the database, inform Smarty to purge the relevant caches clearCache().

    You’re also able to check the cache’s modification time against some timestamp you stored in your database.

    <?php
    $smarty = new Smarty();
    $tpl = $smarty->createTemplate($template_file, $cache_id);
    $databaseLastModified = strtotime("yesterday"); // determine when the database was modified last
    if (!$tpl->isCached() || $tpl->cached->timestamp < $databaseLastModified) {
      $tpl->force_cache = true; // in case of timestamp < modified
      // load data for smarty to process
      $tpl->assign('your', 'stuff');
    }
    $tpl->display();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building a site that will have very minimal code, it's mostly just going
I would like to build a webpart that is going to display list content
We have a very large existing site that we're going to do a completely
I'm going to have to build a custom control for a WinForms application. But
I'm going to propose to a client that I build some batch jobs in
I'm working on a Rails site that connects to an Oracle database, and though
I build database-driven web sites. Previously I have used Perl or PHP with MySQL.
I have been planning since Summer to build a new hobby site over Christmas
I'm going to build an API for a web app and I'm interested in
I'm going to build a Classic Music website and the client already has several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.