Not showing latest records unless i restart the server

36 views
Skip to first unread message

Wassim

unread,
May 19, 2020, 2:00:17 PM5/19/20
to Django REST framework

I'm using django rest framework, to create and retrieve records, but I noticed that when I create a new record and then try to fetch the list of records it doesn't show in the list of records even after 24h, unless I restart the gunicorn server.

I think it has something to do with caching, but I didn't find anything intresting in the documentation about caching.

I want to keep the caching as it is good for performance... but I want the new records to show, is there anyway to refresh the cache after a record is added? or anything similar?


here is a screenshot of my modelviewset.



Capture.PNG

Jelmer Draaijer

unread,
May 20, 2020, 8:31:10 AM5/20/20
to Django REST framework
Your queryset is living in the application context (it is invoked when the server is started). However, It should live in the request context. 

Browsing the source code maybe helps: https://github.com/encode/django-rest-framework/blob/acbd9d8222e763c7f9c7dc2de23c430c702e06d4/rest_framework/generics.py#L70

Long story short: remove the .all() in your queryset definition, this performs the select in the application context. The method get_queryset will execute your query each request. 


Op dinsdag 19 mei 2020 20:00:17 UTC+2 schreef Wassim:
Reply all
Reply to author
Forward
0 new messages