Victor Mezrin
Victor Mezrin

Reputation: 2837

Django ORM cache

I have several models with one-to-many relationships. In my management commands I need to iterate over all entities multiple times. I.e. I have multiple loops like this:

for childEntity in dbObj.childEntities.all():
    ....

Does Django use session cache for dbObj.childEntities.all()? Or I need to cache results somehow?

Upvotes: 0

Views: 242

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600059

No, not by default. You can enable it by using prefetch_related.

Upvotes: 1

Related Questions