Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Completely Remove Query Cache From CakePHP 2.x

I have the follow queries taking place

 public function test()
 {
    $uuid = substr( String::uuid() , 4 , rand( 7 , 10 ) );
    $name = $uuid;

    $event = $this->Event->getEvent( array( "event_id" => "5240e695-9acc-4e32-9b98-1aecb3d0838" ) );
    $event[ "event_name" ] = $name;

    $this->Event->update( $event );

    debug( $this->Event->search( array( "event_id" => $event[ "event_id"] ) )[ 0 ][ "event_name" ] );

    debug( $this->Event->search( array( "event_id" => $event[ "event_id"] , "limit" => 1 ) )[ 0 ][ "event_name" ] );
}

I assign a random name to a particular event retrieved from a mySQL ( InnoDB ) table event, assign a random new name to it, and save it back in the database.

When I run the last two statements in this code, the results are not the same, note that the last parameter in the 2nd query simply adds LIMIT 1 to the end of the second query. ( I am not using CakePHP 2.x's typical methods for searching tables ). The result of the 1st search call will produce the previous result from the previous request while the 2nd search call will produce the actual currently updated name in the event table.

I've been searching high and low on how to remove query cacheing COMPLETELY from the datasource objects but can't figure out how. I've tried using flushMethodCache() on the datasource object, but it does nothing, I've tried setting

$cacheQueries = false, $cacheSources = false;

in the AppModel, but that doesn't do anything either. I've tried looking in /App/Config/Core.php and disabling cacheing, and setting the cache time to 0. None of this works.

like image 533
SobiborTreblinka Avatar asked Feb 03 '26 17:02

SobiborTreblinka


1 Answers

Found out the problem:

Instead of calling

$model->query( $string );

I needed to call

$model->query( $string, false );

like image 139
SobiborTreblinka Avatar answered Feb 06 '26 06:02

SobiborTreblinka