wagtailwagtail-snippet

Working with Wagtail snippets and AWS Cloudfront


I have a significantly large site running on Wagtail, which uses Cloudfront as a frontend cache. Once a page is published/re-published, the url is refreshed on Cloudfront as expected, and changes are readily available. The issue that's occuring is that when snippets are updated, these do not show on the live site until Cloudfront refreshes, or the actual page is re-published. Due to the large amount of pages which use snippets in the site, it's not viable to exclude certain url patterns from Cloudfront. Is there a way to prevent this issue from happening natively from Wagtail or any other reccomended solutions? For example, re-publishing every page when a snippet is edited? Is it advisable to do so?


Solution

  • I would suggest using Wagtail's reference index to find the pages where the edited snippet is used and then clear those pages from the Cloudfront cache when the snippet is edited.

    You will probably want to register a signal to take care of this - the same way Wagtail registers signals for cache invalidation of pages. Snippet views will run hooks like after_create_snippet or after_edit_snippet at the appropriate time.

    See https://docs.wagtail.org/en/stable/advanced_topics/reference_index.html for information on configuring reference counting