Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine2 Cache Corruption?
    primarykey
    data
    text
    <p>I have a Repository Like Bellow. </p> <p>The code checks first if the item is already in the table. </p> <ul> <li><p>If it is not it downloads the data and then stores it to the table. </p></li> <li><p>If it is already in the table it just returns the record.</p></li> </ul> <p>But sometimes after it checks for the item in the table it will still go and try to download and store the item even though it is already there, creating a key conflict, but this should never happen since it just searched and did not find it.</p> <p>Things to note:</p> <ol> <li><strong>If I disable $query->useResultCache(true) i have no problem.</strong></li> <li>This is the only process working on the table.</li> <li>This is the only place in code that items are added to the table.</li> <li>This code is being called from a symfony2 console command.</li> <li>Memcache is the set cache for doctrine2.</li> <li>Memcached is running locally.</li> <li>The error is produced when using arraycache as well.</li> <li>This query is run many times a second.</li> </ol> <pre> class ItemRepository extends EntityRepository { public function findOrFetch($id) { $item = $this->findItem($id); if($item != null) return $item; else { $itemData = $this->fetchItem($id); $item = new Item(); $item->setId($id); $item->setName($itemData['name']); $this->getEntityManager()->persist($item); $this->getEntityManager()->flush(); } } private function findItem($id) { $query = $this ->getEntityManager() ->createQuery('SELECT i from MonkeyWire\WowProfToolsBundle\Entity\Item i WHERE i.id = ?1'); $query->setParameter(1, $id); $query->useResultCache(true); return $query->getOneOrNullResult(); } private function fetchItem($id) { $api = new Client(); $api->setRequest(new Curl()); try { $itemData = $api->getItemsApi()->getItem($id); } catch (NotFoundException $e) { $itemData['name'] = "na"; } return $itemData; } } </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload