Allow purging of subpaths of pages

pull/364/head
Karl Hobley 2014-06-24 12:37:37 +01:00
rodzic 9c4ac7fc31
commit 341f535116
2 zmienionych plików z 21 dodań i 5 usunięć

Wyświetl plik

@ -25,9 +25,11 @@ class CustomHTTPAdapter(HTTPAdapter):
def purge_page_from_cache(page):
# Get session
varnish_url = getattr(settings, 'WAGTAILFRONTENDCACHE_LOCATION', 'http://127.0.0.1:8000/')
# Purge
session = requests.Session()
session.mount('http://', CustomHTTPAdapter(varnish_url))
session.request('PURGE', page.full_url)
# Purge paths from cache
for path in page.get_cached_paths():
session.request('PURGE', page.full_url + path[1:])

Wyświetl plik

@ -629,13 +629,27 @@ class Page(MP_Node, ClusterableModel, Indexed):
"""
return self.serve(self.dummy_request())
def get_internal_paths(self):
"""
This returns a list of paths within this page.
This is used for static sites, sitemaps and cache invalidation.
"""
return ['/']
def get_cached_paths(self):
"""
This returns a list of paths to invalidate in a frontend cache
"""
return self.get_internal_paths()
def get_static_site_paths(self):
"""
This is a generator of URL paths to feed into a static site generator
Override this if you would like to create static versions of subpages
"""
# Yield paths for this page
yield '/'
# Yield paths for this page
for url in self.get_internal_paths():
yield url
# Yield paths for child pages
for child in self.get_children().live():