updating the database cache

astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-29 15:18

ok.. I am using G2 for a e-commerce solution.. and for the description field.. I am using that as a price field... The client i am doing this for sells silver to wholesalers... and the price of silver is always going up... or down.. so he would like to be able to update all prices in the gallery (catalog) from one place...

so i wrote up a script outside of the gallery that grabs the description record for each item (photo) and loops through and adds or subtracts a percentage from the price and updates the database with the new price.. this saves him from having to go to each item and manually editng the captions for 700 plus items...

this works great... it updates the database fine... BUT there is one problem.. G2 works off of a cached copy of the db and G2 will not show the updated prices unless I am logged in as an admin and goto

site admin > Maintenance > Delete database cache

then the new prices show.. the owner of this site does NOT have an admin account as all he really needs to do is edit and upload images and albums...

is there a way that i can force the db cache to delete itself? can i turn this off somehow? are there any creative way to work a round this?

thank you very much in advance.. :)

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-04-29 15:36

if you already have loaded the G2 api in your script, just
include('modules/core/classes/FlushDatabaseCacheTask.class');
$task = new FlushDatabaseCacheTask();
list ($ret, $success, details) = $task->run();

if ($ret->isError()) {
print $ret->getAsHtml();
} else {
// do something with $success and $details
}

you might want to do the same with FlushTemplatesTask.class.

and if you haven't loaded the G2 API yey...

start the script with this:

include('embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true));
// handle $ret
// do your stuff here

at the end of the script...

GalleryEmbed::done(); // absolutely needed.

another idea: just call the URL which calls the specific maintenance task with cron or from your script.