Ejemplo n.º 1
0
 def test_passed_registry(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingConfiglet)
     settings = registry.forInterface(ICachePurgingConfiglet)
     settings.enabled = True
     settings.cachingProxies = ('http://localhost:1234',)
     
     self.assertEquals(False, utils.isCachePurgingEnabled())
     self.assertEquals(True, utils.isCachePurgingEnabled(registry))
Ejemplo n.º 2
0
 def test_no_proxies(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingConfiglet)
     provideUtility(registry, IRegistry)
     
     settings = registry.forInterface(ICachePurgingConfiglet)
     settings.enabled = False
     
     settings.cachingProxies = None
     self.assertEquals(False, utils.isCachePurgingEnabled())
     
     settings.cachingProxies = ()
     self.assertEquals(False, utils.isCachePurgingEnabled())
Ejemplo n.º 3
0
def purge(event):
    """Asynchronously send PURGE requests
    """
    request = event.request
    context = event.object

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

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

    setSite(getattr(IComponentLookup(context, None), '__parent__'))

    if not isCachePurgingEnabled(context):
        return

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

    settings = getUtility(ICachePurgingConfiglet, context=context)
    for path in paths:
        for url in getURLsToPurge(path, settings.cachingProxies):
            purger.purgeAsync(url)

    setSite(None)
Ejemplo n.º 4
0
    def __call__(self):

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

        notify(Purge(self.context))
        return 'Queued'
Ejemplo n.º 5
0
 def __call__(self):
     
     if not isCachePurgingEnabled():
         return 'Caching not enabled'
     
     notify(Purge(self.context))
     return 'Queued'
Ejemplo n.º 6
0
 def test_disabled(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingConfiglet)
     provideUtility(registry, IRegistry)
     
     settings = registry.forInterface(ICachePurgingConfiglet)
     settings.enabled = False
     settings.cachingProxies = ('http://localhost:1234',)
     
     self.assertEquals(False, utils.isCachePurgingEnabled())
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
    def __call__(self):

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

        settings = getUtility(ICachePurgingConfiglet)

        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()
Ejemplo n.º 9
0
 def __call__(self):
     
     if not isCachePurgingEnabled():
         return 'Caching not enabled'
     
     settings = getUtility(ICachePurgingConfiglet)
     
     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()
Ejemplo n.º 10
0
 def test_no_settings(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingConfiglet)
     provideUtility(registry, IRegistry)
     self.assertEquals(False, utils.isCachePurgingEnabled())
Ejemplo n.º 11
0
 def test_no_registry(self):
     self.assertEquals(False, utils.isCachePurgingEnabled())