Ticket #1196 (closed defect: fixed)

Opened 12 months ago

Last modified 10 months ago

Bug in _constructQueryFromCache, Result Cache does not work.

Reported by: mthielen Owned by: romanb
Priority: major Milestone:
Component: Caching Version: 1.0.0
Severity: Keywords:
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description (last modified by mthielen) (diff)

The Resultcache (in my case the APC version) does not work at all.

$cacheDriver = new Doctrine_Cache_Apc();
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver);
$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);

...connecting...

for ($i = 0; $i < 500; $i++) {
  $u = Doctrine_Query::create()
    ->from('User u')
    ->addWhere('u.Login=?', array('DemoUser'))
    ->execute();
}

The first query ($i=0) works as expected as it doesnt read from cache. But the 2nd results in this exception:

<b>Warning</b>:  unserialize() expects parameter 1 to be string, array given in <b>J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php</b> on line <b>1127</b><br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php</b> on line <b>1133</b><br />
<b>Fatal error</b>:  Uncaught exception 'Doctrine_Query_Exception' with message 'Root component not initialized.' in J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php:868
Stack trace:
#0 J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php(568): Doctrine_Query_Abstract-&gt;getRoot()
#1 J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php(963): Doctrine_Query_Abstract-&gt;convertEnums(Array)
#2 J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php(1019): Doctrine_Query_Abstract-&gt;_execute(Array)
#3 W:PrivatJavaWebPortaldoctrine.php(30): Doctrine_Query_Abstract-&gt;execute()
#4 {main}
  thrown in <b>J:ProgrammePHPPEARDoctrinelibDoctrineQueryAbstract.php</b> on line <b>868</b><br />

When patching the function Abstract.php like this:

  protected function _constructQueryFromCache($cached)
  {
    if (is_array($cached))
      $cached = $cached[0];

the error is gone but the resultcache doesnt work either. Nothing is written to APC nor read from.

Regards, Markus

Change History

Changed 12 months ago by mthielen

  • description modified (diff)

Changed 12 months ago by jwage

  • milestone set to 0.11.1

Changed 12 months ago by romanb

  • milestone changed from 0.11.1 to 1.0.0-BETA1

Changed 11 months ago by jwage

  • version changed from 0.11 to 1.0
  • milestone changed from Unknown to 1.0.0-RC1

Changed 11 months ago by romanb

  • status changed from new to assigned

Changed 11 months ago by romanb

  • status changed from assigned to closed
  • resolution set to fixed

(In [4767]) 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.

Changed 11 months ago by romanb

Dont forget to use: $q->useResultCache(), otherwise the query will not use the result cache. Through $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver); you just set the global cache driver but queries need to be explicitly allowed to use it. This is different from the query cache (aka dql parser cache). By just setting the global cache driver for this cache, all queries will use it, since it has no disadvantages for the user.

Changed 11 months ago by romanb

An example usage can be found in the new testcase:  http://trac.phpdoctrine.org/browser/branches/1.0/tests/Cache/ApcTestCase.php

Changed 10 months ago by anonymous

  • milestone New deleted

Milestone New deleted

Note: See TracTickets for help on using tickets.