Merge pull request #414 from kaedroho/frontendcache-purge-url

Allow purging individual URLs from frontend cache
pull/417/head
Karl Hobley 2014-07-03 13:59:13 +01:00
commit 148fcf04e3
2 zmienionych plików z 24 dodań i 4 usunięć

Wyświetl plik

@ -100,3 +100,18 @@ 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.
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 first page of the blog index
purge_url_from_cache(blog_index.url + '?page=1')

Wyświetl plik

@ -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:])