Clear propel cache (instance pool)
Asked Answered
S

2

5

I need to force reread data from DB within one php execution, using propel. I already have a bit hacky solution: call init%modelName% for corresponding classes, but want something better.

Is there any single call or service config option for that? Like killing whole instance pool.

About service: we use symfony2 and don't need cache only in one specific case, hence we can create even separate environment for that.

Smash answered 10/7, 2012 at 10:15 Comment(0)
T
15

You can globally disable the instance pooling by calling: Propel::disableInstancePooling() (Propel::enableInstancePooling() is useful to enable the instance pooling).

Otherwise, you can rely on PEER classes which contain generated methods like clearInstancePool(), and clearRelatedInstancePool().

Throes answered 11/7, 2012 at 17:53 Comment(2)
Actually, my problem was in another place, but thanks for the answer.Smash
@william-durand is there a method like clearInstancePool() in propel 2 (now that the Peer classes have been eliminated?Ecotype
S
0

I needed to update realated objects and found out clear%modelName% should be called.

init%modelName% deletes all entries and related entires could never be read. clear[Related]InstancePool don't help.

$foo = FooQuery->create()->findOne();
// meanwhile somebody else updated DB and Propel don't know about that:
mysql_query("INSERT INTO `foo_bars`, (`foo_id`, `bar_id`) VALUES (".$foo->getId().", 1)");
// here we need some magic to force Propel re-read relation table.
$foo->clearFooBars();
// now entries would be re-read
$foo->getFooBars();
Smash answered 6/11, 2012 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.