Example #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))
Example #2
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))
Example #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))
Example #4
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))
Example #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())
Example #6
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())
Example #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)
Example #8
0
 def __call__(self):
     
     if not isCachePurgingEnabled():
         return 'Caching not enabled'
     
     notify(Purge(self.context))
     return 'Queued'
Example #9
0
    def __call__(self):

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

        notify(Purge(self.context))
        return "Queued"
Example #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)
Example #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())
Example #12
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())
Example #13
0
 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())
Example #14
0
    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())
Example #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))
Example #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))
Example #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()
Example #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()
Example #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()
Example #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()
Example #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
Example #22
0
 def purgingEnabled(self):
     return isCachePurgingEnabled()
Example #23
0
 def test_no_settings(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingSettings)
     provideUtility(registry, IRegistry)
     self.assertEqual(False, utils.isCachePurgingEnabled())
Example #24
0
 def test_no_registry(self):
     self.assertEqual(False, utils.isCachePurgingEnabled())
Example #25
0
 def purgingEnabled(self):
     return isCachePurgingEnabled()
Example #26
0
 def test_no_registry(self):
     self.assertEqual(False, utils.isCachePurgingEnabled())
Example #27
0
 def test_no_settings(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingSettings)
     provideUtility(registry, IRegistry)
     self.assertEqual(False, utils.isCachePurgingEnabled())