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 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))
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 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)
def __call__(self): if not isCachePurgingEnabled(): return 'Caching not enabled' notify(Purge(self.context)) return 'Queued'
def __call__(self): if not isCachePurgingEnabled(): return "Caching not enabled" notify(Purge(self.context)) return "Queued"
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())
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))
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()
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()
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()
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()
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
def purgingEnabled(self): return isCachePurgingEnabled()
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())