On Saturday 18 March 2006 00:50, Russell Keith-Magee wrote:

> Again, look back at the archives.
>
> http://groups.google.com/group/django-developers/browse_thread/thread
>/4a6c67a2df095b43/bb00c30c7ba63bdf
>
> For the record, I would be +1 on Article.objects returning a
> non-cached query set, and Article.objects.all() returning a cached
> query set - however, at last count, I believe Adrian considered the
> matter closed. This thead also worked through a few other mechanics
> with caching.

The case I'm speaking about is related objects, where things can work 
quite differently from the default manager.  In this case, I was only 
bringing it up because I thought it would be nice if getting related 
objects multiple times would only hit the DB once.  I'm fairly 
convinced now that it isn't worth the bother - you can cache manually, 
and the only place where you can't -- the templates -- you aren't 
likely to iterate over related objects multiple times.

As for .all(), I'm a bit disappointed if that thread was the last word 
on this.  Adrian said 'move on, we've already talked about this', but 
he was talking about 'Article.objects.all()', where we had agreed that 
something like would be necessary due to the caching/persistence 
problem.  But no reason has ever been given why the same syntax wart 
would have to be applied to related objects, where the persistence 
problem does not exist.

> > The second step is to make the
> > descriptor objects cache the QuerySets once they have been created.
>
> I disagree here - the query set is the thing that has the cache, not
> the descriptor. Store and reuse the query set if you want to reuse
> the cache. Again, follow the thread (and the thread it refers to) for
> reasoning.

Yes, the QuerySet has a cache, but current descriptor access (e.g. 
ManyRelatedObjectsDescriptor) returns a new Manager every time, and 
changing it to return a QuerySet wouldn't make a difference.  The cache 
*inside* the QuerySet doesn't help you, unless you cache *the* 
QuerySet.  I was experimenting with caching the QuerySet automatically 
(i.e. the descriptor object for the related lookup would do it for you, 
which is actually what happens with 
ReverseSingleRelatedObjectDescriptor), but as you point out, caching it 
yourself ain't so bad.

As for that thread, the reasoning in it doesn't apply to this situation 
(as was explained in the thread, and yet again above).

Regards,

Luke

-- 
You meet a lot of smart guys with stupid wives, but you almost never 
meet a smart woman with a stupid husband. (Erica Jong)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~---------~--~----~------------~-------~--~----~
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