निम्नलिखित मॉडल को देखते हुए, Django पहली बार पहुंचने के बाद संबंधित वस्तुओं को कैश करता है?क्या Django कैश विदेशी कुकी और ManyToManyField फ़ील्ड से संबंधित होने पर संबंधित है?
class Post(models.Model):
authors = models.ManyToManyField(User)
category = models.ForeignKey(Category)
उदाहरण के लिए:
post = Post.objects.get(id=1)
# as i understand this hits the database
authors1 = post.authors.all()
# does this his the database again?
authors2 = post.authors.all()
# as i understand this hits the database
category1 = post.category
# does this hit the database again?
category2 = post.category
नोट: वर्तमान में Django 1.3 के साथ काम है, लेकिन यह पता है कि अन्य संस्करणों में उपलब्ध है अच्छा है।
अभी भी सही नहीं है। कई बहुत सारे प्रश्नों को कैश नहीं किया जाता है - वे वास्तव में एफके लुकअप को रिवर्स करने के बराबर हैं, इसलिए 1.4 में नई 'prefetch_related' कार्यक्षमता का उपयोग करते समय कैश न करें। –
धन्यवाद। जब आवश्यक हो तो मैं कई सारे क्षेत्रों में कैशिंग को संभालेगा। – bpscott
उत्तर को ठीक करने और अभी तक बेहतर परीक्षण करने की आवश्यकता है। मुझे डीजे 1.5 में किसी भी मामले में कैशिंग नहीं दिख रहा है। – Bryce