I have a simple Django app with a single view for displaying the product list:
from time import sleep
<other imports>
class ProductListView(ListView):
model = Product
paginate_by = 50
allow_empty = True
def get(self, *args, **kwargs):
sleep(2)
return super().get(*args, **kwargs)
And the template:
<div class="container">
{% for product in page_obj %}
<div class="col-3 my-2">
<product details>
</div>
{% endfor %}
</div>
I use sleep(2)
to emulate the slow uploading of a huge amount of objects from the database.
Now I need to implement the next workflow:
- template from this view should be cached. So the first page upload should take >2 sec, the next one <2sec, uploaded from the cache.
- change Product item in the database (via admin page for example)
- page on refresh is loaded from cache, but product info should be updated to the newest
I'm, researching the Django caching mechanism, but I'm not sure which one should I try. So is it possible in Django to implement this workflow?