Django Caching & QuerySet

dooh kim·2020년 9월 10일
0

queryset-tutorial

목록 보기
5/5

Caching and QuerySets

Keep this caching behavior in mind, because it may bite you if you don’t use your QuerySets correctly. For example, the following will create two QuerySets, evaluate them, and throw them away:

evaluate
평가 되어진 다는 것은 데이터 베이스에 갔다온다는 것을 의미한다.


# 이런식으로 데이터를 불러오면 정확한 데이터를 받지 못할 수도 있다.
# 그리고 두배로 데이터 베이스 호출을 하게 된다.
print([e.headline for e in Entry.objects.all()])
print([e.pub_date for e in Entry.objects.all()])

queryset = Entry.objects.all()
# 이렇게 변수에 캐쉬를 한 후

# 이 때 캐싱된 데이터를 가져다 쓰는게 효율적이고 정확하다.
print([p.headline for p in queryset])
print([p.pub_date for p in queryset])
profile
testify to the light

0개의 댓글