Sunday, 15 April 2012

Django default caching of foreign key models -



Django default caching of foreign key models -

for life of me can't find reply question online, although it's basic one.

i have 2 models, 1 referencing other:

class a(models.model): name = models.charfield(...) ... class b(models.model): = models.foreignkey(a)

now, i'm keeping instance of b in memory, , ever access b.a.name . accessing b.a.name cause database query every time, changes in a.name (changes done process) seen in process? or have query a explicitly each time?

i'm surprised haven't been able find info on this. it's fairly documented forwards relationships cached on first usage - happens cache attribute created, , subsequent lookups check first.

so yes, means changes object in process not seen, , need re-query each time. (note depends on database's transaction isolation setting, might not see new value on re-querying - may need commit current transaction first.)

django

No comments:

Post a Comment