mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-27 16:14:01 +00:00
Allow purging of subpaths of pages
This commit is contained in:
parent
9c4ac7fc31
commit
341f535116
2 changed files with 21 additions and 5 deletions
|
|
@ -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:])
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Reference in a new issue