cakephp checking for duplicate rows
<p>I have been at this for 5 days now. I read all the answers I could here, I have tried any options I could I cannot find how to fix this cache issue.</p>

<p>I am using cakephp 2.4.4 which could be upgraded but I did not see my issue in any of the change.log
Percona MYSQL 5.6 Innodb</p>

<p>We have a model that we call in a loop to insert rows</p>

<pre><code>App::import('Model', 'TableA');
$TableA = new TableA();
foreach($rows as $row){
    $TableA-&gt;InsertRow($row);
}
</code></pre>

<p>Then we have the Model for TableA</p>

<p>I added a Unique Index on TableA.Sku to avoid duplicate entry</p>

<pre><code>class TableA extends AppModel {
    var $name = 'TableA';
    var $cacheQueries = false;
    var $validate = array();
    function InsertRow($data){
        $this-&gt;clear();
        try {
            $result = $this-&gt;find('first', array(
                'fields' =&gt; array(
                     'TableA.id',
                 ),
                 'conditions' =&gt; array(
                     'TableA.Sku' =&gt; $data['Sku'],
                 ),
            ));
            pr($result);
            if(!isset($result['TableA']['id'])){
                $data['TimeStamp'] = strtotime("now");
                $this-&gt;save($data);
            }
            return TRUE;
        }
        catch (Exception $e) {
            pr($e);
            $resultNow = $this-&gt;find('first', array(
                'fields' =&gt; array(
                     'TableA.id',
                 ),
                 'conditions' =&gt; array(
                     'TableA.Sku' =&gt; $data['Sku'],
                 ),
            ));
            pr($resultNow);
        }
   }
}
</code></pre>

<p>The first loop $Rows has multiple time the same sku following each other
the first loop insert the row
the 2nd loop gives:</p>

<pre><code>array
(
)

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'tue026991015' for key 'Sku'
INSERT INTO `ki`.`TableA` (`Sku`, `TimeStamp`) VALUES ('tue026991015', 1453858976)

Array
(
    [TableA] =&gt; Array
        (
            [id] =&gt; 31951
        )
)
</code></pre>

<p>I am also running in Debug Mode 2</p>

<p>In the 2nd loop the query should return the id and the loop should not try to insert the row but it is not.
I added var $cacheQueries = false; on top of the Model to avoid cashing. I am at a loss as to why this behavior is happening and how to avoid any mysql cashing for this function.</p>