We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

DB Caching Issue

Development and Programming

ryal001's avatar
ryal001
42 posts
16 years ago
ryal001's avatar ryal001

I am developing a module and as part of that I have a function that runs to confirm a transaction. The function creates a manual database connection and uses mysqli commands to set autocommit to false etc. (i.e. I am not using the DB class for this particular function). If the transaction is committed, a number of table rows are inserted and others updated.

The site has database caching enabled and I don’t want to turn this off. However, when the user next accesses a relevant template, the information is not updated (presumably because I didn’t use the DB class to update the database).

Is there a way to stop particular templates from using the database cache?

I was thinking maybe I could enable PHP on the relevant templates and call:

$DB->enable_cache(FALSE)

If this works, would the cache have to be re-enabled at the end of the template?

EDIT: Perhaps it would be better to just delete the cache:

$DB->delete_cache()

Of course, I presume this would delete all cache files, thus decreasing performance for the rest of the site.

Thanks,

Rob

       
ryal001's avatar
ryal001
42 posts
16 years ago
ryal001's avatar ryal001

Update:

Rather than put the code in the templates I have added it to the beginning and end of my affected functions (including any functions that use the DB class but return output to templates where that output relies on database information that was updated without using the DB class):

my_function()
{
    global $DB;

    $DB->enable_cache(FALSE);

    $db_conn = mysqli_connect($DB->hostname, $DB->username, $DB->password, $DB->database);

    blah, blah blah;

    $DB->enable_cache(TRUE);
}

This seems to have worked OK.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Yes, or for a more unintrusive implementation you could grab the existing setting to make sure that when your method quits, it’s not turning the caching on if it was originally disabled.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.