Index: src/main/java/org/wso2/carbon/registry/core/caching/CachingHandler.java =================================================================== --- src/main/java/org/wso2/carbon/registry/core/caching/CachingHandler.java (revision 115056) +++ src/main/java/org/wso2/carbon/registry/core/caching/CachingHandler.java (working copy) @@ -74,29 +74,40 @@ removeFromCache(connectionId, tenantId, cachePath); String parentPath = RegistryUtils.getParentPath(cachePath); - - removeFromCache(connectionId, tenantId, parentPath); - String pagedParentPathPrefix = "^" + Pattern.quote((parentPath == null)?"":parentPath) + "(" + RegistryConstants.PATH_SEPARATOR + - ")?(;start=.*)?$"; for (Object key : cache.keySet()) { String path = ((RegistryCacheKey) key).getPath(); if (recursive) { if (path.startsWith(cachePath)) { removeFromCache(connectionId, tenantId, path); - continue; } } + } + clearAncestry(connectionId, tenantId, parentPath); + } + + private void clearAncestry(String connectionId, int tenantId, String parentPath) { + boolean cleared = removeFromCache(connectionId, tenantId, parentPath); + String pagedParentPathPrefix = "^" + Pattern.quote((parentPath == null) ? "" : parentPath) + + "(" + RegistryConstants.PATH_SEPARATOR + ")?(;start=.*)?$"; + for (Object key : cache.keySet()) { + String path = ((RegistryCacheKey) key).getPath(); if (path.matches(pagedParentPathPrefix)) { - removeFromCache(connectionId, tenantId, path); + cleared = cleared || removeFromCache(connectionId, tenantId, path); } } + if (!cleared && parentPath != null && !parentPath.equals(RegistryConstants.ROOT_PATH)) { + clearAncestry(connectionId, tenantId, RegistryUtils.getParentPath(parentPath)); + } } - private void removeFromCache(String connectionId, int tenantId, String path) { + private boolean removeFromCache(String connectionId, int tenantId, String path) { RegistryCacheKey cacheKey = RegistryUtils.buildRegistryCacheKey(connectionId, tenantId, path); if (cache.containsKey(cacheKey)) { cache.remove(cacheKey); + return true; + } else { + return false; } }