Exemple #1
0
    def test_passed_registry(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True

        self.assertEqual(False, utils.isCachePurgingEnabled())
        self.assertEqual(True, utils.isCachePurgingEnabled(registry))
    def test_passed_registry(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True

        self.assertEqual(False, utils.isCachePurgingEnabled())
        self.assertEqual(True, utils.isCachePurgingEnabled(registry))
Exemple #3
0
    def test_passed_registry(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234',)

        self.assertEqual(False, utils.isCachePurgingEnabled())
        self.assertEqual(True, utils.isCachePurgingEnabled(registry))
    def test_passed_registry(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234', )

        self.assertEqual(False, utils.isCachePurgingEnabled())
        self.assertEqual(True, utils.isCachePurgingEnabled(registry))
Exemple #5
0
    def test_no_proxies(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = False

        settings.cachingProxies = None
        self.assertEqual(False, utils.isCachePurgingEnabled())

        settings.cachingProxies = ()
        self.assertEqual(False, utils.isCachePurgingEnabled())
    def test_no_proxies(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = False

        settings.cachingProxies = None
        self.assertEqual(False, utils.isCachePurgingEnabled())

        settings.cachingProxies = ()
        self.assertEqual(False, utils.isCachePurgingEnabled())
Exemple #7
0
def purge(event):
    """Asynchronously send PURGE requests
    """

    request = event.request

    annotations = IAnnotations(request, None)
    if annotations is None:
        return

    paths = annotations.get(KEY, None)
    if paths is None:
        return

    registry = queryUtility(IRegistry)
    if registry is None:
        return

    if not isCachePurgingEnabled(registry=registry):
        return

    purger = queryUtility(IPurger)
    if purger is None:
        return

    settings = registry.forInterface(ICachePurgingSettings, check=False)
    for path in paths:
        for url in getURLsToPurge(path, settings.cachingProxies):
            purger.purgeAsync(url)
Exemple #8
0
 def __call__(self):
     
     if not isCachePurgingEnabled():
         return 'Caching not enabled'
     
     notify(Purge(self.context))
     return 'Queued'
Exemple #9
0
    def __call__(self):

        if not isCachePurgingEnabled():
            return "Caching not enabled"

        notify(Purge(self.context))
        return "Queued"
Exemple #10
0
def purge(event):
    """Asynchronously send PURGE requests
    """
    
    request = event.request
    
    annotations = IAnnotations(request, None)
    if annotations is None:
        return
    
    paths = annotations.get(KEY, None)
    if paths is None:
        return
    
    registry = queryUtility(IRegistry)
    if registry is None:
        return
    
    if not isCachePurgingEnabled(registry=registry):
        return
    
    purger = queryUtility(IPurger)
    if purger is None:
        return
    
    settings = registry.forInterface(ICachePurgingSettings, check=False)
    for path in paths:
        for url in getURLsToPurge(path, settings.cachingProxies):
            purger.purgeAsync(url)
Exemple #11
0
    def test_enabled(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        self.assertEqual(True, utils.isCachePurgingEnabled())
    def test_enabled(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        self.assertEqual(True, utils.isCachePurgingEnabled())
 def test_enabled(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingSettings)
     provideUtility(registry, IRegistry)
     
     settings = registry.forInterface(ICachePurgingSettings)
     settings.enabled = True
     settings.cachingProxies = ('http://localhost:1234',)
     self.assertEquals(True, utils.isCachePurgingEnabled())
    def test_disabled(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = False
        settings.cachingProxies = ('http://localhost:1234', )

        self.assertEqual(False, utils.isCachePurgingEnabled())
Exemple #15
0
def queuePurge(event):
    """Find URLs to purge and queue them for later
    """

    request = getRequest()
    if request is None:
        return

    annotations = IAnnotations(request, None)
    if annotations is None:
        return

    if not isCachePurgingEnabled():
        return

    paths = annotations.setdefault(KEY, set())
    paths.update(getPathsToPurge(event.object, request))
Exemple #16
0
def queuePurge(event):
    """Find URLs to purge and queue them for later
    """
    
    request = getRequest()
    if request is None:
        return
    
    annotations = IAnnotations(request, None)
    if annotations is None:
        return
    
    if not isCachePurgingEnabled():
        return
    
    paths = annotations.setdefault(KEY, set())
    paths.update(getPathsToPurge(event.object, request))
Exemple #17
0
    def __call__(self):
        if not isCachePurgingEnabled():
            return "Caching not enabled"

        registry = getUtility(IRegistry)
        settings = registry.forInterface(ICachePurgingSettings)
        purger = getUtility(IPurger)
        out = StringIO()

        for path in getPathsToPurge(self.context, self.request):
            for url in getURLsToPurge(path, settings.cachingProxies):
                status, xcache, xerror = purger.purgeSync(url)
                out.write(
                    RESULT_TPL.format(url=url,
                                      status=status,
                                      xcache=xcache,
                                      xerror=xerror))
        return out.getvalue()
Exemple #18
0
 def __call__(self):
     
     if not isCachePurgingEnabled():
         return 'Caching not enabled'
     
     registry = getUtility(IRegistry)
     settings = registry.forInterface(ICachePurgingSettings)
     
     purger = getUtility(IPurger)
     
     out = StringIO()
     
     for path in getPathsToPurge(self.context, self.request):
         for url in getURLsToPurge(path, settings.cachingProxies):
             status, xcache, xerror = purger.purgeSync(url)
             print >>out, "Purged", url, "Status", status, "X-Cache", xcache, "Error:", xerror
     
     return out.getvalue()
Exemple #19
0
    def __call__(self):

        if not isCachePurgingEnabled():
            return 'Caching not enabled'

        registry = getUtility(IRegistry)
        settings = registry.forInterface(ICachePurgingSettings)

        purger = getUtility(IPurger)

        out = StringIO()

        for path in getPathsToPurge(self.context, self.request):
            for url in getURLsToPurge(path, settings.cachingProxies):
                status, xcache, xerror = purger.purgeSync(url)
                print >> out, "Purged", url, "Status", status, "X-Cache", xcache, "Error:", xerror

        return out.getvalue()
Exemple #20
0
    def __call__(self):
        if not isCachePurgingEnabled():
            return "Caching not enabled"

        registry = getUtility(IRegistry)
        settings = registry.forInterface(ICachePurgingSettings)
        purger = getUtility(IPurger)
        out = StringIO()

        for path in getPathsToPurge(self.context, self.request):
            for url in getURLsToPurge(path, settings.cachingProxies):
                status, xcache, xerror = purger.purgeSync(url)
                out.write(
                    RESULT_TPL.format(
                        url=url, status=status, xcache=xcache, xerror=xerror
                    )
                )
        return out.getvalue()
Exemple #21
0
def syncPurge(obj):
    request = getRequest()

    paths = getPathsToPurge(obj, request)

    registry = queryUtility(IRegistry)
    if registry is None:
        return

    if not isCachePurgingEnabled(registry=registry):
        return

    purger = queryUtility(IPurger)
    if purger is None:
        return

    settings = registry.forInterface(ICachePurgingSettings, check=False)
    purged_urls = []
    for path in paths:
        for url in getURLsToPurge(path, settings.cachingProxies):
            purger.purgeSync(url)
            purged_urls.append(url)

    return purged_urls
Exemple #22
0
 def purgingEnabled(self):
     return isCachePurgingEnabled()
Exemple #23
0
 def test_no_settings(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingSettings)
     provideUtility(registry, IRegistry)
     self.assertEqual(False, utils.isCachePurgingEnabled())
 def test_no_registry(self):
     self.assertEqual(False, utils.isCachePurgingEnabled())
Exemple #25
0
 def purgingEnabled(self):
     return isCachePurgingEnabled()
 def test_no_registry(self):
     self.assertEqual(False, utils.isCachePurgingEnabled())
 def test_no_settings(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingSettings)
     provideUtility(registry, IRegistry)
     self.assertEqual(False, utils.isCachePurgingEnabled())