#NEWLINE# def learn_cache_key( request , response , cache_timeout = None , key_prefix = None , cache = None ) : #NEWLINE# #INDENT# '\n    Learns what headers to take into account for some request URL from the\n    response object. It stores those headers in a global URL registry so that\n    later access to that URL will know what headers to take into account\n    without building the response object itself. The headers are named in the\n    Vary header of the response, but we want to prevent response generation.\n\n    The list of headers to use for cache key generation is stored in the same\n    cache as the pages themselves. If the cache ages some data out of the\n    cache, this just means that we have to build the response once to get at\n    the Vary header and so at the list of headers to use for the cache key.\n    ' #NEWLINE# if ( key_prefix is None ) : #NEWLINE# #INDENT# key_prefix = settings . CACHE_MIDDLEWARE_KEY_PREFIX #NEWLINE# #UNINDENT# if ( cache_timeout is None ) : #NEWLINE# #INDENT# cache_timeout = settings . CACHE_MIDDLEWARE_SECONDS #NEWLINE# #UNINDENT# cache_key = _generate_cache_header_key ( key_prefix , request ) #NEWLINE# if ( header is None ) : #NEWLINE# #INDENT# cache = caches [ settings . CACHE_MIDDLEWARE_ALIAS ] #NEWLINE# #UNINDENT# if response . has_header ( 'Vary' ) : #NEWLINE# #INDENT# is_accept_language_redundant = ( settings . USE_I18N or settings . USE_L10N ) #NEWLINE# headerlist = [ ] #NEWLINE# for header in cc_delim_re . split ( response [ 'Vary' ] ) : #NEWLINE# #INDENT# header = header . upper ( ) . replace ( '-' , '_' ) #NEWLINE# if ( ( header == 'ACCEPT_LANGUAGE' ) and is_accept_language_redundant ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# headerlist . append ( ( 'HTTP_' + header ) ) #NEWLINE# #UNINDENT# headerlist . sort ( ) #NEWLINE# cache . set ( cache_key , headerlist , cache_timeout ) #NEWLINE# return _generate_cache_key ( request , request . method , headerlist , key_prefix ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cache . set ( cache_key , [ ] , cache_timeout ) #NEWLINE# return _generate_cache_key ( request , request . method , [ ] , key_prefix )