php - "Duration" of elements on a Propel Instance Pool -
i'm new in php, , in propel.
as have read, propel got instance pool, reuse querys.
for example
<?php // first call $author1 = authorquery::create()->getbyfoofield('foo'); $foo = $author1->getid(); // select query ... // second call $author2 = authorquery::create()->getbyfoofield('foo'); // skips sql query , returns existing $author1 object $foo = $author2->getid();
the thing is
for how many time objects alive? origined because have parse excel, , build objects persist them in db.
so, maybe in excel read in 100 rows, read 25 times 'foo', so, querying db every time getting pk bad thing, if can avoid 24 querys.
looks instance propel solves problem, don't know how many time.
that depends on time, memory used, or scope querys executed ? (i mean, maybe after method executes first query, instance pool cleared, so, unless second query in same method, query again db. or maybe while object alive, don't know)
i've search little not found anything, mi intuition tell me depends on memory used, but, nothing official.
or maybe there's better way of doing this.
just adding answer follows comments above.
basically, instance pool collection of objects organized primary key. not cache of queries, rather 1 of specific instances. time request specific record added instance pool class. when request record it's primary key second time, propel give cached object instead of hitting database. time issue ->find()
propel will hit database, regardless of instance pool.
in generated base classes can see behavior looking findpk
method , seeing how uses getinstancefrompool()
, addinstancetopool()
.
for example:
$entity1 = entityquery::create()->findpk(13); // hit database $entity2 = entityquery::create()->findpk(13); // not hit database // hit db, if there 1 record & in instance pool $entity3 = entityquery::create()->findonebyname("record thirteen"); // hit db every time, regardless of instance pool // though same query $entity4 = entityquery::create()->findonebyname("record thirteen"); // hit database, if instance in pool $entity5 = entityquery::create()->findbyuniquefield("unique value");
hope helps. again, not speculation, have gone code , double checked this. can in generated base classes , in propel/runtime/lib/query/modelcriteria.php
(specifically find()
method) see how works.
Comments
Post a Comment