In the context of our "cache synchronization" discussion, does
ensureLoaded()
check to see if an object is in cache,
Keep in mind, my examples are from our (currently internal) ORM
"product", other tools may/will do other things. The ensureloaded call
is there to "ensure" that the field you're about to load has actually
been retrieved from the database. We support the concept of ghost
objects, that is objects where you've specified the key (probably from a
foreign key relation) but not gone to the database to populate the
object. EnsureLoaded is nothing more than an if statement that says:
protected void EnsureLoaded()
{
if (IsGhost)
LoadFromDB();
}
If cached objects become stale, I gather that they must be
instantiated from scratch.
Well, I guess you could do some sort of compare/update to "refresh" the
objects. But for the most part yes, they're instantiated from scratch.
Actually, in our case every "retrieval" from cache (under development)
results in you getting back a new copy of the object anyway, all cache
is doing is avoiding a trip to the db. Of course, avoiding that trip can
result in significant performance gains, and in many cases the data
isn't going to go stale anyway. Consider some possible items to cache:
50 "State" objects, those haven't gone stale since we admitted Hawaii.
:) Or perhaps a collection of allowed actions on a screen, those won't
likely go stale until you next update the application. Or a list of
Warehouses in the company, goes stale every few years? But these objects
are probably referenced many times in an application, so you're
significantly reducing IO.
And if you have a lot of I/O activity, then that puts extra load on
the garbage collector...
I wouldn't be too worried about the GC. That's one of the most optimized
routines around. Do you create more stuff for it to do? Yup. Should you
care? Nope. One trip to the DB is probably more expensive in terms of
wait time then a complete GC cycle.
-Walden
--
Walden H Leverich III
Tech Software
(516) 627-3800 x3051
WaldenL@xxxxxxxxxxxxxxx
http://www.TechSoftInc.com
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)
As an Amazon Associate we earn from qualifying purchases.