From 1ce157ea432a32c737e2ad47e2b337bb699da61c Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 3 Jul 2014 09:17:55 +0100 Subject: [PATCH 1/3] Added purge_url_from cache to wagtailfontendcache.utils --- wagtail/contrib/wagtailfrontendcache/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wagtail/contrib/wagtailfrontendcache/utils.py b/wagtail/contrib/wagtailfrontendcache/utils.py index b95ed7e957..66b77c9712 100644 --- a/wagtail/contrib/wagtailfrontendcache/utils.py +++ b/wagtail/contrib/wagtailfrontendcache/utils.py @@ -24,12 +24,17 @@ class CustomHTTPAdapter(HTTPAdapter): return super(CustomHTTPAdapter, self).get_connection(self.cache_url, proxies) -def purge_page_from_cache(page): +def purge_url_from_cache(url): # Get session cache_server_url = getattr(settings, 'WAGTAILFRONTENDCACHE_LOCATION', 'http://127.0.0.1:8000/') session = requests.Session() session.mount('http://', CustomHTTPAdapter(cache_server_url)) - # Purge paths from cache - for path in page.get_cached_paths(): - session.request('PURGE', page.full_url + path[1:]) + # Send purge request to cache + session.request('PURGE', url) + + +def purge_page_from_cache(page): + # Purge cached paths from cache + for path in page.specific.get_cached_paths(): + purge_url_from_cache(page.full_url + path[1:]) From e4a9756c7942411c95588501427954fdf90f5814 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 3 Jul 2014 10:14:51 +0100 Subject: [PATCH 2/3] Added little section in the docs describing purge_url_from_cache --- docs/frontend_cache_purging.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/frontend_cache_purging.rst b/docs/frontend_cache_purging.rst index a949bdc6e5..e8564f6c12 100644 --- a/docs/frontend_cache_purging.rst +++ b/docs/frontend_cache_purging.rst @@ -100,3 +100,16 @@ Let's take the the above BlogIndexPage as an example. We need to register a sign @register(pre_delete, sender=BlogPage) def blog_deleted_handler(instance): blog_page_changed(instance) + + +Purging individual URLs +----------------------- + +``wagtail.contrib.wagtailfrontendcache.utils`` provides another utils function called ``purge_url_from_cache``. As the name suggests, this purges an individual URL from the cache. + +.. code-block:: python + + from wagtail.contrib.wagtailfrontendcache.utils import purge_url_from_cache + + # Purge the homepage + purge_url_from_cache(homepage.full_url) From c9385ca1ce241ff15f88faa262800ae561098d58 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 3 Jul 2014 13:10:03 +0100 Subject: [PATCH 3/3] frontend cache purge docs change --- docs/frontend_cache_purging.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/frontend_cache_purging.rst b/docs/frontend_cache_purging.rst index e8564f6c12..34a6fda50b 100644 --- a/docs/frontend_cache_purging.rst +++ b/docs/frontend_cache_purging.rst @@ -107,9 +107,11 @@ Purging individual URLs ``wagtail.contrib.wagtailfrontendcache.utils`` provides another utils function called ``purge_url_from_cache``. As the name suggests, this purges an individual URL from the cache. +For example, this could be useful for purging a single page of blogs: + .. code-block:: python from wagtail.contrib.wagtailfrontendcache.utils import purge_url_from_cache - # Purge the homepage - purge_url_from_cache(homepage.full_url) + # Purge the first page of the blog index + purge_url_from_cache(blog_index.url + '?page=1')