@@ -301,17 +301,32 @@ public function dropByIds(array $ids)
301301
302302 public function uncacheById ($ id )
303303 {
304- unset($ this ->identityMap [$ id ]);
305-
306- return Cache::worker ($ this )->uncacheById ($ id );
304+ return $ this ->getUncacherById ($ id )->uncache ();
305+ }
306+
307+ /**
308+ * @return UncachersPool
309+ */
310+ public function getUncacherById ($ id )
311+ {
312+ return UncacherGenericDAO::create (
313+ $ this ,
314+ $ id ,
315+ Cache::worker ($ this )->getUncacherById ($ id )
316+ );
307317 }
308318
309319 public function uncacheByIds ($ ids )
310320 {
321+ if (empty ($ ids ))
322+ return ;
323+
324+ $ uncacher = $ this ->getUncacherById (array_shift ($ ids ));
325+
311326 foreach ($ ids as $ id )
312- unset ($ this ->identityMap [ $ id] );
327+ $ uncacher -> merge ($ this ->getUncacherById ( $ id) );
313328
314- return Cache:: worker ( $ this )-> uncacheByIds ( $ ids );
329+ return $ uncacher -> uncache ( );
315330 }
316331
317332 public function uncacheLists ()
@@ -339,6 +354,11 @@ public function dropObjectIdentityMapById($id)
339354 return $ this ;
340355 }
341356
357+ public function registerWorkerUncacher (UncacherBase $ uncacher )
358+ {
359+ DBPool::getByDao ($ this )->registerUncacher ($ uncacher );
360+ }
361+
342362 protected function inject (
343363 InsertOrUpdateQuery $ query ,
344364 Identifiable $ object
@@ -362,19 +382,35 @@ protected function doInject(
362382 $ db = DBPool::getByDao ($ this );
363383
364384 if (!$ db ->isQueueActive ()) {
385+ $ preUncacher = is_scalar ($ object ->getId ())
386+ ? $ this ->getUncacherById ($ object ->getId ())
387+ : null ;
388+
365389 $ count = $ db ->queryCount ($ query );
366390
367- $ this ->uncacheById ($ object ->getId ());
391+ $ uncacher = $ this ->getUncacherById ($ object ->getId ());
392+ if ($ preUncacher ) {
393+ $ uncacher ->merge ($ uncacher );
394+ }
395+ $ uncacher ->uncache ();
368396
369397 if ($ count !== 1 )
370398 throw new WrongStateException (
371399 $ count .' rows affected: racy or insane inject happened: '
372400 .$ query ->toDialectString ($ db ->getDialect ())
373401 );
374402 } else {
403+ $ preUncacher = is_scalar ($ object ->getId ())
404+ ? $ this ->getUncacherById ($ object ->getId ())
405+ : null ;
406+
375407 $ db ->queryNull ($ query );
376408
377- $ this ->uncacheById ($ object ->getId ());
409+ $ uncacher = $ this ->getUncacherById ($ object ->getId ());
410+ if ($ preUncacher ) {
411+ $ uncacher ->merge ($ uncacher );
412+ }
413+ $ uncacher ->uncache ();
378414 }
379415
380416 // clean out Identifier, if any
@@ -403,4 +439,4 @@ private function addObjectListToMap($list)
403439 return $ list ;
404440 }
405441 }
406- ?>
442+ ?>
0 commit comments