diff --git a/wagtail/contrib/wagtailfrontendcache/utils.py b/wagtail/contrib/wagtailfrontendcache/utils.py index af0e9f8839..608b722d98 100644 --- a/wagtail/contrib/wagtailfrontendcache/utils.py +++ b/wagtail/contrib/wagtailfrontendcache/utils.py @@ -56,18 +56,27 @@ def get_backends(backend_settings=None, backends=None): def purge_url_from_cache(url, backend_settings=None, backends=None): - for backend_name, backend in get_backends(backend_settings=backend_settings, backends=backends).items(): + for backend_name, backend in get_backends(backend_settings, backends).items(): logger.info("[%s] Purging URL: %s", backend_name, url) backend.purge(url) +def purge_urls_from_cache(urls, backend_settings=None, backends=None): + for backend_name, backend in get_backends(backend_settings, backends).items(): + for url in urls: + logger.info("[%s] Purging URL: %s", backend_name, url) + + backend.purge_batch(urls) + + def purge_page_from_cache(page, backend_settings=None, backends=None): page_url = page.full_url if page_url is None: # nothing to be done if the page has no routable URL return - for backend_name, backend in get_backends(backend_settings=backend_settings, backends=backends).items(): - # Purge cached paths from cache - for path in page.specific.get_cached_paths(): - logger.info("[%s] Purging URL: %s", backend_name, page_url + path[1:]) - backend.purge(page_url + path[1:]) + # Purge cached paths from cache + urls = [ + page_url + path[1:] + for path in page.specific.get_cached_paths() + ] + purge_urls_from_cache(urls, backend_settings, backends)