#1686: Result cache does not respect configured TTLs
-----------------------------------+----------------------------------------
 Reporter:  hobodave               |       Owner:  jwage
     Type:  defect                 |      Status:  new  
 Priority:  critical               |   Milestone:  1.0.4
Component:  Attributes             |     Version:  1.0.3
 Keywords:  cache result ttl       |    Has_test:  0    
 Mystatus:  Pending Core Response  |   Has_patch:  1    
-----------------------------------+----------------------------------------
 When configuring the result cache as follows:

 {{{
     $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
     $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 300);
 }}}

 The TTL is completely ignored by the result cache as shown in the
 following example:
 {{{
    $query->useResultCache(true)
 }}}

 This creates a cached entry in my APC user cache, yet the TTL is shown as
 None.
 This is due to the following functions in Doctrine_Query_Abstract:
 {{{
     public function useResultCache($driver = true, $timeToLive = null)
     {
         if ($driver !== null && $driver !== true && ! ($driver instanceOf
 Doctrine_Cache_Interface)) {
             $msg = 'First argument should be instance of
 Doctrine_Cache_Interface or null.';
             throw new Doctrine_Query_Exception($msg);
         }
         $this->_resultCache = $driver;

         return $this->setResultCacheLifeSpan($timeToLive);
     }

     // snip

     public function setResultCacheLifeSpan($timeToLive)
     {
         if ($timeToLive !== null) {
             $timeToLive = (int) $timeToLive;
         }
         $this->_resultCacheTTL = $timeToLive;

         return $this;
     }
 }}}
 Note that it useResultCache always calls setResultCacheLifeSpan, even when
 $timeToLive is NULL, thus always overwriting the default TTL unless
 explicitly specified.

 The function should be changed as follows:

 {{{
     public function useResultCache($driver = true, $timeToLive = null)
     {
         if ($driver !== null && $driver !== true && ! ($driver instanceOf
 Doctrine_Cache_Interface)) {
             $msg = 'First argument should be instance of
 Doctrine_Cache_Interface or null.';
             throw new Doctrine_Query_Exception($msg);
         }
         $this->_resultCache = $driver;

         if (! is_null($timeToLive)) {
             $this->$this->setResultCacheLifeSpan($timeToLive);
         }
         return $this;
     }
 }}}

 On a related note useQueryCache should probably be updated to provide the
 same interface as useResultCache

     public function useResultCache($driver = true, $timeToLive = null)

 vs.

     public function useQueryCache($driver = true, $timeToLive = false)

 I'm not sure how this will work for backwards compatibility though. I'll
 attach the patch addressing the bug, as well as a patch to make the
 interface uniform.

-- 
Ticket URL: <http://trac.doctrine-project.org/ticket/1686>
Doctrine <http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"doctrine-svn" group.
 To post to this group, send email to [email protected]
 To unsubscribe from this group, send email to [EMAIL PROTECTED]
 For more options, visit this group at 
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

Reply via email to