private void flushRegexpDependenciesOfPath( Cache depCache, String path, boolean propageToOtherClusterNodes) { if (logger.isDebugEnabled()) { logger.debug("Flushing dependencies for path : " + path); } @SuppressWarnings("unchecked") List<String> keys = depCache.getKeys(); for (String key : keys) { if (path.matches(key)) { cacheProvider.invalidateRegexp(key, propageToOtherClusterNodes); } } }
private void flushDependenciesOfPath( Cache depCache, Set<String> flushed, String path, boolean propageToOtherClusterNodes) { if (logger.isDebugEnabled()) { logger.debug("Flushing dependencies for path : " + path); } Element element = !flushed.contains(path) ? depCache.get(path) : null; if (element != null) { flushed.add(path); if (logger.isDebugEnabled()) { logger.debug("Flushing path : " + path); } cacheProvider.invalidate(path, propageToOtherClusterNodes); depCache.remove(element.getKey()); } }
/** * This method is called when a bundle of events is dispatched. * * @param events The event set received. */ public void onEvent(EventIterator events) { final Cache depCache = cacheProvider.getDependenciesCache(); final Cache regexpDepCache = cacheProvider.getRegexpDependenciesCache(); final Set<String> flushed = new HashSet<String>(); while (events.hasNext()) { Event event = (Event) events.next(); boolean propageToOtherClusterNodes = !isExternal(event); try { String path = event.getPath(); if (!path.startsWith("/jcr:system")) { boolean flushParent = false; boolean flushRoles = false; if (path.contains("j:view")) { flushParent = true; } final int type = event.getType(); if (type == Event.PROPERTY_ADDED || type == Event.PROPERTY_CHANGED || type == Event.PROPERTY_REMOVED) { if (path.endsWith("/j:published")) { flushParent = true; } if (path.endsWith("j:roles")) { flushRoles = true; } path = path.substring(0, path.lastIndexOf("/")); } else if (type == Event.NODE_ADDED || type == Event.NODE_MOVED || type == Event.NODE_REMOVED) { flushParent = true; } if (path.contains("vanityUrlMapping")) { flushParent = true; } if (path.contains("j:acl") || path.contains("jnt:group") || flushRoles || type == Event.NODE_MOVED) { // Flushing cache of acl key for users as a group or an acl has been updated CacheKeyGenerator cacheKeyGenerator = cacheProvider.getKeyGenerator(); if (cacheKeyGenerator instanceof DefaultCacheKeyGenerator) { DefaultCacheKeyGenerator generator = (DefaultCacheKeyGenerator) cacheKeyGenerator; generator.flushUsersGroupsKey(propageToOtherClusterNodes); } flushParent = true; } path = StringUtils.substringBeforeLast( StringUtils.substringBeforeLast(path, "/j:translation"), "/j:acl"); flushDependenciesOfPath(depCache, flushed, path, propageToOtherClusterNodes); try { flushDependenciesOfPath( depCache, flushed, ((JCREventIterator) events).getSession().getNode(path).getIdentifier(), propageToOtherClusterNodes); } catch (PathNotFoundException e) { if (event instanceof EventImpl && (((EventImpl) event).getChildId() != null)) { flushDependenciesOfPath( depCache, flushed, ((EventImpl) event).getChildId().toString(), propageToOtherClusterNodes); } } flushRegexpDependenciesOfPath(regexpDepCache, path, propageToOtherClusterNodes); if (flushParent) { path = StringUtils.substringBeforeLast(path, "/"); flushDependenciesOfPath(depCache, flushed, path, propageToOtherClusterNodes); try { flushDependenciesOfPath( depCache, flushed, ((JCREventIterator) events).getSession().getNode(path).getIdentifier(), propageToOtherClusterNodes); } catch (PathNotFoundException e) { if (event instanceof EventImpl && (((EventImpl) event).getParentId() != null)) { flushDependenciesOfPath( depCache, flushed, ((EventImpl) event).getParentId().toString(), propageToOtherClusterNodes); } } flushRegexpDependenciesOfPath(regexpDepCache, path, propageToOtherClusterNodes); } } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } }