Ejemplo n.º 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."
Ejemplo n.º 2
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."
Ejemplo n.º 3
0
 def test_some_credentials_raises(self):
     credentials = {
         'CLIENT_TOKEN': 'some-arbitrary-token',
         'CLIENT_SECRET': None,
         'ACCESS_TOKEN': None,
     }
     with self.assertRaises(ValueError):
         AkamaiBackend(credentials)
Ejemplo n.º 4
0
 def test_no_credentials_raises(self):
     credentials = {
         'CLIENT_TOKEN': None,
         'CLIENT_SECRET': None,
         'ACCESS_TOKEN': None,
     }
     with self.assertRaises(ValueError):
         AkamaiBackend(credentials)
Ejemplo n.º 5
0
 def test_all_credentials_get_set(self):
     credentials = {
         'CLIENT_TOKEN': 'token',
         'CLIENT_SECRET': 'secret',
         'ACCESS_TOKEN': 'access token',
     }
     akamai_backend = AkamaiBackend(credentials)
     self.assertEquals(akamai_backend.client_token, 'token')
     self.assertEquals(akamai_backend.client_secret, 'secret')
     self.assertEquals(akamai_backend.access_token, 'access token')
 def handle(self, *args, **options):
     AkamaiBackend(settings.WAGTAILFRONTENDCACHE["akamai"]).delete_all()
Ejemplo n.º 7
0
 def handle(self, *args, **options):
     AkamaiBackend(settings.WAGTAILFRONTENDCACHE['akamai']).purge_all()