lukejapanwalker Posted September 24, 2015 Share Posted September 24, 2015 (edited) I am updating my product prices automatically using sql, but the prices do not change until the cache is cleared manually from the admin control panel.Is there a way to clear the cache via script?Right now I have a sql command hidden in the product description to update the price of the product, what code should I add after that to clear the cache right away?Thank you for your help.Luke. Edited September 25, 2015 by lukejapanwalker Resolved Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 24, 2015 Share Posted September 24, 2015 "Right now I have a sql command hidden in the product description to update the price of the product,"That's interesting.In code, you would use this statement to clear the cache of SQL queries:$GLOBALS['cache']->clear('sql');But, in CC6, while in admin, the cache is not enabled. Also, if your 'hidden' query uses CubeCart's Database class, an update() will clear the cache anyway. Quote Link to comment Share on other sites More sharing options...
lukejapanwalker Posted September 25, 2015 Author Share Posted September 25, 2015 Hello bsmither,Thank you for your reply,I tried "$GLOBALS['cache']->clear('sql');" in my sql code for my description and nothing changed.do you know what might be wrong? I'm sure there's probably something I'm just not understanding but I think I just need a way to clear the cache each time someone clicks on a product or something like that.Thanks again for your help.Luke. Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 25, 2015 Share Posted September 25, 2015 You can tell CubeCart just to not use the cache at all. In admin, Store Settings, Advanced tab, Disable Caching."I tried "$GLOBALS['cache']->clear('sql');" in my sql code for my description."Please tell us more about how you are putting this code where you say you are.A product's description is not executed or evaluated. It is simply given to the template and displayed as is. Quote Link to comment Share on other sites More sharing options...
lukejapanwalker Posted September 25, 2015 Author Share Posted September 25, 2015 Ok that sound perfect! I just did that and it worked for the first refresh and now it's like it's back on again.Is there still an issue with disabling the cache in v6? Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 25, 2015 Share Posted September 25, 2015 No issue at all.But please, do explain what it is you are doing -- in detail. Quote Link to comment Share on other sites More sharing options...
lukejapanwalker Posted September 25, 2015 Author Share Posted September 25, 2015 Hello thanks for your reply.Ok, in my description there is an iframe that links to a php file (located in the root directory of my store) to update the database, like below.$link = mysqli_connect($servername, $username, $password, $my_db); $sql = "UPDATE gwm_CubeCart_inventory SET price='99.00' WHERE product_id='".$proid."'"; if ($link->query($sql) === TRUE) { echo "New record created successfully"; //echo "O"; } else { echo "Error: " . $sql . "<br>" . $link->error; //echo "X"; }But the price of the item only refreshes when I clear the cache.I tried admin, Store Settings, Advanced tab, Enable Caching >> selected disable from the drop down menu and hit save.It worked once but after running the sql code above it doesnt refresh anymore.I check to make sure it change by looking in phpmyadmin and it did change there but not in my store.ThanksLuke. Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 25, 2015 Share Posted September 25, 2015 The PHP script being called by the iframe is using PHP's own functions to connect - not CubeCart's database class. So the cache is not involved at all. In fact, no part of CubeCart is involved at all.So, for the moment, until I see more of what you are doing, I find nothing wrong. But, I now see that even though the iframe script makes a direct call to the database, CubeCart, on the next page request of that product, needs to pull the fresh data.And that's where we have concerns about the cache. Quote Link to comment Share on other sites More sharing options...
lukejapanwalker Posted September 25, 2015 Author Share Posted September 25, 2015 (edited) I just checked again and disabling "enable caching" under "Performance" works but ony once and I still have to do it manually, is there anything I can add after my SQL queiry to clear the cache after changing the price?Based on what you said, I believe if I can only clear the cache it should work?CheersLuke. Edited September 25, 2015 by lukejapanwalker Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted September 25, 2015 Share Posted September 25, 2015 Please read https://forums.cubecart.com/topic/50008-problem-with-the-cache and specifically check your global.inc.php to see whether you have an entry defining which caching method is being used such as $glob['cache'] = 'file'; This is auto added during upgrades and then means that caching cannot ever be switched off from within store settings !! Remove that entry and then you can control again whether cache is enabled or disabled but if you re-enable it and then have problems with memcache you will need to add the line back in again. This is why I suggested specifically defining which caching method is used within the Store Settings and not using the global.inc.php file at all Ian Quote Link to comment Share on other sites More sharing options...
lukejapanwalker Posted September 25, 2015 Author Share Posted September 25, 2015 Thanks a bunch heavenswift-hosting! that did it! And thanks bsmither, I know you are a big contributor to this forum and your old posts too, have helped me a lot. I hope someone else find this useful in the future. Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 25, 2015 Share Posted September 25, 2015 "check your global.inc.php for $glob['cache'] = 'file';"Ah Ha! No wonder I missed it. I'm not fully into CC607 as yet. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.