I'm done building a website, there's a lots of views that contains many queries My question is How can I avoid repeating some queries from views that will be visited by users many time?.
Here is an example of views.py
@access_to(['is_admin','is_job_seeker'])
def negotiationView(request,slug,id,code):
obj = get_object_or_404(Group,slug=slug)
nego = get_object_or_404(Negotiation,id=id,code=code)
related_negos = Negotiation.objects.filter(tag=nego.tag)
# New tag can be created every 2 months or more
all_jobs = obj.job_offers.filter(published=True) # new job can be added every week
As you can, each time I visit that page, the same query will repeat..
Any hint will be helpful, Thank you in advance!
You can add a caching layer to your application. One of the technologies that can be used with Django is Memcached.
Here's info in Django docs about setting up caching with Memcached: https://docs.djangoproject.com/en/2.0/topics/cache/#memcached
Also same page has info about using caching in Django in general, including per-view cache
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加