diff --git a/all/pom.xml b/all/pom.xml index d39013ab..481a8e4b 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -50,7 +50,8 @@ com.adobe.aem.guides aem-cif-guides-venia.all - container + mixed + true all diff --git a/classic/all/pom.xml b/classic/all/pom.xml index f60e5801..8f306461 100644 --- a/classic/all/pom.xml +++ b/classic/all/pom.xml @@ -50,7 +50,8 @@ com.adobe.aem.guides aem-cif-guides-venia.all - container + mixed + true all diff --git a/core/src/main/java/com/venia/core/models/commerce/services/ClearFullDispatcherCacheBasedOnCategory.java b/core/src/main/java/com/venia/core/models/commerce/services/ClearFullDispatcherCacheBasedOnCategory.java new file mode 100644 index 00000000..d942ee84 --- /dev/null +++ b/core/src/main/java/com/venia/core/models/commerce/services/ClearFullDispatcherCacheBasedOnCategory.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * + * Copyright 2025 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + * + ******************************************************************************/ + +package com.venia.core.models.commerce.services; + +import com.adobe.cq.commerce.core.cacheinvalidation.spi.DispatcherCacheInvalidationStrategy; +import com.adobe.cq.commerce.magento.graphql.*; +import com.day.cq.wcm.api.Page; +import org.apache.sling.api.resource.ResourceResolver; +import org.osgi.service.component.annotations.Component; +import javax.jcr.Session; +import java.util.*; +import org.apache.sling.api.resource.Resource; + +@Component( + service = DispatcherCacheInvalidationStrategy.class, + property = {"invalidateRequestParameter=categoryUids" }) +public class ClearFullDispatcherCacheBasedOnCategory implements DispatcherCacheInvalidationStrategy { + + private static final String HEADER_FRAGMENT_PATH = "/content/experience-fragments/venia/us/en/site/header/master"; + private static final String NAVIGATION_NODE_PATH = "jcr:content/root/navigation"; + private static final String STRUCTURE_DEPTH_PROPERTY = "structureDepth"; + private static final String CATEGORY_LIST_KEY = "categoryList"; + private static final String LEVEL_KEY = "level"; + + @Override + public String getPattern() { + return null; + } + + @Override + public String[] getCorrespondingPagePaths(Session session, String storePath, String dataList) { + return new String[0]; + } + + @Override + public String getGraphqlQuery(String[] data) { + CategoryFilterInput filter = new CategoryFilterInput(); + FilterEqualTypeInput identifiersFilter = new FilterEqualTypeInput().setIn(Arrays.asList(data)); + filter.setCategoryUid(identifiersFilter); + QueryQuery.CategoryListArgumentsDefinition searchArgs = s -> s.filters(filter); + + CategoryTreeQueryDefinition queryArgs = q -> q.uid().level(); + + return Operations.query(query -> query + .categoryList(searchArgs, queryArgs)).toString(); + } + + @Override + public String[] getPathsToInvalidate(Page page, ResourceResolver resourceResolver, Map data, String storePath) { + if (resourceResolver == null || data == null || !data.containsKey(CATEGORY_LIST_KEY)) { + return new String[0]; + } + + Integer navigationStructureDepth = getNavigationStructureDepth(resourceResolver); + if (navigationStructureDepth == null) { + return new String[0]; + } + + List> categories = (List>) data.get(CATEGORY_LIST_KEY); + + if (shouldInvalidateFullCache(categories, navigationStructureDepth)) { + return new String[] { storePath }; + } + return new String[0]; + } + + private Integer getNavigationStructureDepth(ResourceResolver resourceResolver) { + Resource headerResource = resourceResolver.getResource( + HEADER_FRAGMENT_PATH + "/" + NAVIGATION_NODE_PATH); + if (headerResource == null) { + return null; + } + + return headerResource.getValueMap().get(STRUCTURE_DEPTH_PROPERTY, Integer.class); + } + + private boolean shouldInvalidateFullCache(List> categories, int navigationStructureDepth) { + return categories.stream() + .map(category -> ((Number) category.get(LEVEL_KEY)).intValue()) + .filter(Objects::nonNull) + .anyMatch(level -> level <= navigationStructureDepth + 1); + } +} diff --git a/pom.xml b/pom.xml index 8f3fb9c8..5364555d 100644 --- a/pom.xml +++ b/pom.xml @@ -87,7 +87,7 @@ admin admin 2.18.6 - 2.15.0 + 2.15.3-SNAPSHOT 1.7.10 9.1.0-magento242ee 5.1.2 diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index d85bb631..55f4d179 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -47,10 +47,12 @@ org.apache.jackrabbit filevault-package-maven-plugin + 1.3.2 com.adobe.aem.guides aem-cif-guides-venia.ui.apps - application + mixed + true com.adobe.aem.guides diff --git a/ui.apps/src/main/content/META-INF/vault/filter.xml b/ui.apps/src/main/content/META-INF/vault/filter.xml index 25aa2b0f..86977adb 100644 --- a/ui.apps/src/main/content/META-INF/vault/filter.xml +++ b/ui.apps/src/main/content/META-INF/vault/filter.xml @@ -3,4 +3,7 @@ + + + diff --git a/ui.apps/src/main/content/jcr_root/_oak_index/cifCacheInvalidationSupport/.content.xml b/ui.apps/src/main/content/jcr_root/_oak_index/cifCacheInvalidationSupport/.content.xml new file mode 100644 index 00000000..a22708c9 --- /dev/null +++ b/ui.apps/src/main/content/jcr_root/_oak_index/cifCacheInvalidationSupport/.content.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + diff --git a/ui.config/src/main/content/jcr_root/apps/venia/osgiconfig/config.author/com.adobe.cq.cif.cacheinvalidation.internal.InvalidateCacheNotificationImpl.cfg.json b/ui.config/src/main/content/jcr_root/apps/venia/osgiconfig/config.author/com.adobe.cq.cif.cacheinvalidation.internal.InvalidateCacheNotificationImpl.cfg.json new file mode 100644 index 00000000..0e0dcd23 --- /dev/null +++ b/ui.config/src/main/content/jcr_root/apps/venia/osgiconfig/config.author/com.adobe.cq.cif.cacheinvalidation.internal.InvalidateCacheNotificationImpl.cfg.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/ui.config/src/main/content/jcr_root/apps/venia/osgiconfig/config/com.adobe.cq.commerce.core.cacheinvalidation.internal.InvalidateCacheSupport.cfg.json b/ui.config/src/main/content/jcr_root/apps/venia/osgiconfig/config/com.adobe.cq.commerce.core.cacheinvalidation.internal.InvalidateCacheSupport.cfg.json new file mode 100644 index 00000000..2bfb8b3f --- /dev/null +++ b/ui.config/src/main/content/jcr_root/apps/venia/osgiconfig/config/com.adobe.cq.commerce.core.cacheinvalidation.internal.InvalidateCacheSupport.cfg.json @@ -0,0 +1,11 @@ +{ + "enableDispatcherCacheInvalidation": true, + "dispatcherBasePathConfiguration": "/content/venia/([a-z]{2})/([a-z]{2}):/content/venia/$1/$2", + "dispatcherUrlPathConfiguration": [ + "productUrlPath:/products/product-page.html/(.+):/p/$1", + "categoryUrlPath:/products/category-page.html/(.+):/c/$1", + "productUrlPath-1:/products/product-page.html/(.+):/pp/$1", + "categoryUrlPath-1:/products/category-page.html/(.+):/cc/$1" + ], + "dispatcherBaseUrl": "http://localhost:80" +} \ No newline at end of file