@@ -343,15 +343,18 @@ def process_response(
343343 # (of the chopped request, not the real one).
344344 cr = _chop_querystring (request )
345345 uri = unquote (cr .build_absolute_uri ())
346- keyring = self ._wagcache .get ("keyring" , {})
347- # Get current cache keys belonging to this URI.
348- # This should be a list of keys.
349- uri_keys : List [str ] = keyring .get (uri , [])
350- # Append the key to this list if not already present and save.
351- if cache_key not in uri_keys :
352- uri_keys .append (cache_key )
353- keyring [uri ] = uri_keys
354- self ._wagcache .set ("keyring" , keyring )
346+
347+ if wagtailcache_settings .WAGTAIL_CACHE_KEYRING :
348+ keyring = self ._wagcache .get ("keyring" , {})
349+ # Get current cache keys belonging to this URI.
350+ # This should be a list of keys.
351+ uri_keys : List [str ] = keyring .get (uri , [])
352+ # Append the key to this list if not already present and save.
353+ if cache_key not in uri_keys :
354+ uri_keys .append (cache_key )
355+ keyring [uri ] = uri_keys
356+ self ._wagcache .set ("keyring" , keyring )
357+
355358 if isinstance (response , SimpleTemplateResponse ):
356359
357360 def callback (r ):
@@ -382,7 +385,11 @@ def clear_cache(urls: List[str] = []) -> None:
382385 return
383386
384387 _wagcache = caches [wagtailcache_settings .WAGTAIL_CACHE_BACKEND ]
385- if urls and "keyring" in _wagcache :
388+ if (
389+ urls
390+ and wagtailcache_settings .WAGTAIL_CACHE_KEYRING
391+ and "keyring" in _wagcache
392+ ):
386393 keyring = _wagcache .get ("keyring" )
387394 # Check the provided URL matches a key in our keyring.
388395 matched_urls = []
0 commit comments