0

I have been assigned a new project. In this django project the previous developer uses django.core.cache module a lot.

I decided to keep it like this.

My question is this. Can I make a unique string out of the request object that would let me know if the request object is the same as before?

Request comes with a set of 15 parameters (even more) and it is hard to choose one or some of them to create a key. It has to be all, because different combinations lead to different results.

This is the code I want to change (some code left out for brevity):

@login_required
def compare(request, username):
    cache_key = 'key__%d' % (request.GET.to_unique_id_or_similar())
    cache_value = cache.get(cache_key)
    if cache_value is not None:
        return cache_value
2
  • 1
    You could create a string from the parameters, generate then a MD5 for the name and compare it / use it as the cache key. Commented Aug 7, 2014 at 10:38
  • Thanks, I have thought of that, too. But how can I be sure that request.GET dictionary object will return the values always in the same way? Commented Aug 7, 2014 at 10:45

1 Answer 1

0

Django provides a super easy way to do this with the @cache_page decorator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.