mercredi 3 juillet 2019

Django memcached does not cache view when redirecting from same view

I currently have memcached installed on my Django server. I have two views: index and results. From the index I use a post form method to redirect me to the results view based on the search. The memcached works fine here. The results view gets cached correctly. However this only works from the index view. In the results view I give the user the option to search again which redirects the user back to the results view on same input, but this view is not cached. I used a time.sleep() timer to see if the page was being cached.

I've tried messing around with urls.py as I currently have a regular expression for the url match, but no luck here. I'm not exactly sure where the error could be persisting from.

@cache_page(61*1)
def index(request):

    if request.method == 'POST':
        return redirect(results, input_1=some_input)

@cache_page(61*1)
def results(request, input_1):
    time.sleep(2) # Using this to test view cache
    if request.method == 'POST':
        return redirect(results, input_1=some_input)

The code above is stripped down, but it gets the idea of what I'm trying to do across. Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire