diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
index 39ef2b3..c3cf3c0 100644
a
|
b
|
To avoid this problem, simply save the
|
747 | 747 | >>> print([p.headline for p in queryset]) # Evaluate the query set. |
748 | 748 | >>> print([p.pub_date for p in queryset]) # Re-use the cache from the evaluation. |
749 | 749 | |
| 750 | When querysets are not cached |
| 751 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 752 | |
| 753 | Querysets do not always cache their results. When evaluating only *part* of the queryset, the cache is checked, but if it is not present then the items returned are not cached. |
| 754 | |
| 755 | Specifically, this means that :ref:`limiting the queryset <limiting-querysets>` using an array slice or an index will not populate the cache. |
| 756 | |
| 757 | For example, repeatedly getting a certain index in a queryset object will requery the database each time:: |
| 758 | |
| 759 | >>> queryset = Entry.objects.all() |
| 760 | >>> print queryset[5] # Queries the database |
| 761 | >>> print queryset[5] # Queries the database again |
| 762 | |
| 763 | However, if the entire queryset has already been evaluated, the cache will be checked instead:: |
| 764 | |
| 765 | >>> queryset = Entry.objects.all() |
| 766 | >>> [entry for entry in queryset] # Queries the database |
| 767 | >>> print queryset[5] # Uses cache |
| 768 | >>> print queryset[5] # Uses cache |
| 769 | |
| 770 | .. note:: |
| 771 | |
| 772 | Simply printing the queryset will not populate the cache. This is because the call to ``__repr__()`` only returns a slice of the entire Queryset. |
| 773 | |
| 774 | Examples of actions that will populate the cache:: |
| 775 | |
| 776 | >>> [entry for entry in queryset] |
| 777 | >>> bool(queryset) |
| 778 | >>> entry in queryset |
| 779 | >>> list(queryset) |
| 780 | |
750 | 781 | .. _complex-lookups-with-q: |
751 | 782 | |
752 | 783 | Complex lookups with Q objects |