Changeset 4767

Show
Ignore:
Timestamp:
08/09/08 21:42:52 (5 months ago)
Author:
romanb
Message:

Fixed APC cache driver. Dont know where the old Doctrine_Cache_Apc#save() code came from... if anyone knows please tell me. Added a testcase to test using apc as a result cache. Fixed #1196.

Location:
branches/1.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Cache/Apc.php

    r4520 r4767  
    8585    public function save($id, $data, $lifeTime = false) 
    8686    { 
    87         return (bool) apc_store($id, array($data, time()), $lifeTime); 
     87        return (bool) apc_store($id, $data, $lifeTime); 
    8888    } 
    8989 
  • branches/1.0/tests/Cache/ApcTestCase.php

    r3884 r4767  
    3434class Doctrine_Cache_Apc_TestCase extends Doctrine_UnitTestCase  
    3535{ 
    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    } 
    3777}