예제 #1
0
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."
예제 #2
0
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()
예제 #3
0
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()
예제 #4
0
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'])
예제 #5
0
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'])