| 36 | | |
| | 36 | public function prepareTables() |
| | 37 | { |
| | 38 | $this->tables = array('User'); |
| | 39 | parent::prepareTables(); |
| | 40 | } |
| | 41 | |
| | 42 | public function prepareData() |
| | 43 | { |
| | 44 | $user = new User(); |
| | 45 | $user->name = 'Hans'; |
| | 46 | $user->save(); |
| | 47 | } |
| | 48 | |
| | 49 | public function testApcAsResultCache() |
| | 50 | { |
| | 51 | if (!extension_loaded("apc")) { |
| | 52 | return; |
| | 53 | } |
| | 54 | |
| | 55 | // clear user cache to make sure we always get the same behavior: |
| | 56 | // 1st iteration cache miss, subsequent iterations cache hit. |
| | 57 | apc_clear_cache("user"); |
| | 58 | |
| | 59 | $cacheDriver = new Doctrine_Cache_Apc(); |
| | 60 | $this->conn->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver); |
| | 61 | |
| | 62 | $queryCountBefore = $this->conn->count(); |
| | 63 | |
| | 64 | for ($i = 0; $i < 10; $i++) { |
| | 65 | $u = Doctrine_Query::create() |
| | 66 | ->from('User u') |
| | 67 | ->addWhere('u.name = ?', array('Hans')) |
| | 68 | ->useResultCache() |
| | 69 | ->execute(); |
| | 70 | $this->assertEqual(1, count($u)); |
| | 71 | $this->assertEqual("Hans", $u[0]->name); |
| | 72 | } |
| | 73 | |
| | 74 | // Just 1 query should be run |
| | 75 | $this->assertEqual($queryCountBefore + 1, $this->conn->count()); |
| | 76 | } |