Permalink
Browse files

Added write to cache after update

Prevents population of cache from possibly lagging read slave on
next request
  • Loading branch information...
1 parent 573f554 commit 594a8538e176ba8547d2209a4ab77a873034808f Dan Copeland committed Sep 16, 2011
Showing with 13 additions and 6 deletions.
  1. +7 −1 Deneb/Object/Common.php
  2. +6 −5 tests/Deneb/DummyTest.php
View
@@ -668,7 +668,13 @@ public function update()
$where = "{$this->_primaryKey} = {$this->_values[$this->_primaryKey]}";
$this->_getWriteDB()->update($this->_table, $valuesToWrite, $where);
}
- $this->invalidateCache();
+
+ // Actively update the cache with the latest values from the row (which
+ // could differ from our values due to triggers) from the write master
+ $args = array($this->_primaryKey => $this->_values[$this->_primaryKey]);
+ $this->_values = array();
+ $this->_loadFromDB($args, 'write');
+ $this->updateCache();
}
/**
View
@@ -163,16 +163,17 @@ public function testUpdate()
$stmt1 = Zend_Test_DbStatement::createSelectStatement(array($data1));
$stmt2 = Zend_Test_DbStatement::createUpdateStatement(1);
- $this->_connectionMock->appendStatementToStack($stmt1);
+ $stmt3 = Zend_Test_DbStatement::createSelectStatement(array($data2));
+
+ $this->_connectionMock->appendStatementToStack($stmt3);
$this->_connectionMock->appendStatementToStack($stmt2);
+ $this->_connectionMock->appendStatementToStack($stmt1);
- $this->_object->__construct();
- $contents = $this->_object->get();
- $this->assertTrue(empty($contents));
+ $this->_object->__construct(array('id' => 1));
+ $this->assertSame($data1, $this->_object->get());
$this->_object->set($data2);
$this->_object->update();
-
$this->assertSame($data2, $this->_object->get());
}

0 comments on commit 594a853

Please sign in to comment.