On 10/11/06, Gábor Farkas <[EMAIL PROTECTED]> wrote:
>
> Michael Radziej wrote:
> hmm.. maybe i am only implementing strange web-applications, but up to
> now, i never ever needed the caching behaviour of the QuerySets...so i
> probably will have to ALWAYS use the iterator() method.
>
>
> (just for curiosity... could someone describe me a typical use-case,
> where caching querysets are important?

objlist = Article.objects.filter(...)
for obj in objlist:
   do something

for obj in objlist:
   do something else

This will result in 1 call to the database - the database is queried
with the first for loop, but the cache is used for the second.

> somehow i assumed that the QuerySets never load in the whole result-set,
> except when they are forced (cast to list for example). but now i see
> that of course, if you cache the results, then you will have all the
> results in memory anyway...

This is what happens. The iterator loads from the database on demand,
and caches for later use. For small result sets (< 100 results), the
first query will return all the results, but if your query returns a
large list of objects, multiple db queries will be issued to pull back
data a little bit at a time. Either way, the results are cached in the
queryset for later use.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to