def effective_version_saved(sender, instance, **kwargs): """ Invalidate the cache if the effective_version is not a draft """ if not instance.draft: batch = PurgeBatch() for page in instance.part.page.all(): urls = page.get_urls_for_version(instance) batch.add_urls(urls) batch.purge()
def section_saved(sender, instance, **kwargs): if not instance.subpart.version.draft: batch = PurgeBatch() for page in instance.subpart.version.part.page.all(): urls = page.get_urls_for_version( instance.subpart.version, section=instance ) batch.add_urls(urls) batch.purge()
def purge(url=None): akamai_config = settings.WAGTAILFRONTENDCACHE.get('akamai', {}) cloudfront_config = settings.WAGTAILFRONTENDCACHE.get('files', {}) if url: # Use the Wagtail frontendcache PurgeBatch to perform the purge batch = PurgeBatch() batch.add_url(url) # If the URL matches any of our CloudFront distributions, invalidate # with that backend if any(k for k in cloudfront_config.get('DISTRIBUTION_ID', {}) if k in url): logger.info('Purging {} from "files" cache'.format(url)) batch.purge(backends=['files']) # Otherwise invalidate with our default backend else: logger.info('Purging {} from "akamai" cache'.format(url)) batch.purge(backends=['akamai']) return "Submitted invalidation for %s" % url else: # purge_all only exists on our AkamaiBackend backend = AkamaiBackend(akamai_config) logger.info('Purging entire site from "akamai" cache') backend.purge_all() return "Submitted invalidation for the entire site."
def section_saved(sender, instance, **kwargs): if not instance.subpart.version.draft: batch = PurgeBatch() for page in instance.subpart.version.part.page.all(): urls = page.get_urls_for_version(instance.subpart.version, section=instance) batch.add_urls(urls) batch.purge()
def cloudfront_cache_invalidation(sender, instance, **kwargs): if not settings.ENABLE_CLOUDFRONT_CACHE_PURGE: return if not instance.file: return url = instance.file.url logger.info('Purging {} from "files" cache'.format(url)) batch = PurgeBatch() batch.add_url(url) batch.purge(backends=['files'])
def cloudfront_cache_invalidation(sender, instance, **kwargs): if not settings.ENABLE_CLOUDFRONT_CACHE_PURGE: return if not instance.file: return media_base = settings.MEDIA_URL if hasattr(settings, 'AWS_S3_CUSTOM_DOMAIN'): media_base = settings.AWS_S3_CUSTOM_DOMAIN url = urljoin(media_base, instance.url) logger.info("Invalidating cache for " + url) batch = PurgeBatch() batch.add_url(url) batch.purge(backends=['files'])