From 4570653d0c52859d7483ec2b73e6fc08043f2ffb Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 11 Aug 2017 16:54:01 +0100 Subject: [PATCH] Implement purge_urls_from_cache --- wagtail/contrib/wagtailfrontendcache/utils.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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)