0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Implement purge_urls_from_cache

This commit is contained in:
Karl Hobley 2017-08-11 16:54:01 +01:00 committed by Matt Westcott
parent dcfd45c326
commit 4570653d0c

View File

@ -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:])
urls = [
page_url + path[1:]
for path in page.specific.get_cached_paths()
]
purge_urls_from_cache(urls, backend_settings, backends)