#11269: Allow key_prefix to be callable
-----------------------------------+----------------------------------------
          Reporter:  kmike         |         Owner:  nobody
            Status:  new           |     Milestone:        
         Component:  Cache system  |       Version:  SVN   
        Resolution:                |      Keywords:        
             Stage:  Accepted      |     Has_patch:  1     
        Needs_docs:  0             |   Needs_tests:  0     
Needs_better_patch:  0             |  
-----------------------------------+----------------------------------------
Comment (by zeth):

 For the second example, that of get parameters, I just generalise the
 whole thing, i.e. any and all get parameters are used for the key_prefix.

 i.e. something like:

 {{{

 def get_requests(request):
     """Turn the GET parameters into a string.
     Used for caching."""
     key_prefix = ""
     # Get the parameters out
     parameters = request.GET.items()
     # Sort them so we only have one order in the cache
     parameters.sort()
     # Turn it into a string
     for pair in parameters:
         for item in pair:
             key_prefix += "%s-" % item
     return key_prefix

 @cache_page(600, my_key_prefix)
 def my_view(request):
     #blah blah

 }}}

 This pattern seems to work for all the situations I have encountered so
 far. This seems to be more DRY than the example above.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11269#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to