def break_enforcement_cache(sender, instance, **kwargs): base = instance.get_site().root_url batch = PurgeBatch() enf_api_url = base + reverse('enforcement_action_api') enf_charts_url = base + '/enforcement/payments-harmed-consumers/enforcement-database/' # noqa: E501 batch.add_urls([enf_api_url, enf_charts_url]) 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 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 purge_document_from_cache(document): # No need for check if they are public or private - if they've changed, # they should be out of cache. logger.debug('Purge document "%s" from the front-end cache', document.file.name) frontend_cache_configuration = get_frontend_cache_configuration() if frontend_cache_configuration: s3_batch = PurgeBatch() s3_batch.add_url(document.file.url) s3_batch.purge(backend_settings=frontend_cache_configuration) # Purge Wagtail document view URLs using normal site's cache. wagtail_batch = PurgeBatch() wagtail_batch.add_urls( build_absolute_urls_for_all_sites_for_path(document.url)) wagtail_batch.purge()
def purge_collection_documents_from_cache(collection): # Do not purge documents if they are in a public collection. Documents # themselves have not changed so no need to make redundant calls for big # collections. if not collection.get_view_restrictions(): return logger.debug( 'Purge documents of collection "%s" from the front-end cache', collection.name, ) # Purge download URLs and actual files if they possibly used to be public. wagtail_batch = PurgeBatch() s3_batch = PurgeBatch() for document in get_document_model().objects.filter(collection=collection): wagtail_batch.add_urls( build_absolute_urls_for_all_sites_for_path(document.url)) s3_batch.add_url(document.file.url) wagtail_batch.purge() frontend_cache_configuration = get_frontend_cache_configuration() if frontend_cache_configuration: s3_batch.purge(backend_settings=frontend_cache_configuration)