Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sdl.dxa.api.datamodel.model.ContentModelData;
import com.sdl.dxa.api.datamodel.model.EntityModelData;
import com.sdl.dxa.api.datamodel.model.PageModelData;
import com.sdl.dxa.caching.NamedCacheProvider;
import com.sdl.dxa.caching.statistics.CacheStatisticsProvider;
import com.sdl.dxa.common.dto.EntityRequestDto;
import com.sdl.dxa.common.dto.PageRequestDto;
Expand Down Expand Up @@ -44,10 +45,13 @@
import org.springframework.web.context.request.RequestContextHolder;

import jakarta.servlet.http.HttpSession;

import javax.cache.Cache;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

/**
Expand All @@ -65,6 +69,7 @@ public class GraphQLContentProvider extends AbstractContentProvider implements C
private final WebRequestContext webRequestContext;
private ApiClientProvider pcaClientProvider;
private CacheManager cacheManager;
private NamedCacheProvider namedCacheProvider;
private CacheStatisticsProvider cacheStatisticsProvider;

@Autowired
Expand All @@ -73,6 +78,7 @@ public GraphQLContentProvider(WebRequestContext webRequestContext,
ModelBuilderPipeline builderPipeline, GraphQLProvider graphQLProvider,
ApiClientProvider pcaClientProvider,
@Qualifier("compositeCacheManager") CacheManager cacheManager,
NamedCacheProvider namedCacheProvider,
CacheStatisticsProvider cacheStatisticsProvider) {
super(webRequestContext, cacheManager);
this.webRequestContext = webRequestContext;
Expand All @@ -81,6 +87,7 @@ public GraphQLContentProvider(WebRequestContext webRequestContext,
this.staticContentResolver = staticContentResolver;
this.builderPipeline = builderPipeline;
this.graphQLProvider = graphQLProvider;
this.namedCacheProvider = namedCacheProvider;
this.cacheStatisticsProvider = cacheStatisticsProvider;
}

Expand Down Expand Up @@ -160,23 +167,36 @@ private boolean isNoMediaCache(String path, String localizationPath) {
return !FileUtils.isEssentialConfiguration(path, localizationPath) && webRequestContext.isSessionPreview();
}

/**
* {@inheritDoc}
*
*/
@Override
public @NotNull StaticContentItem getStaticContent(String path, String localizationId, String localizationPath)
throws ContentProviderException {
if (namedCacheProvider == null || !namedCacheProvider.isCacheEnabled("staticContentItems")) {
return processStaticContent(path, localizationId, localizationPath);
}
else {
String cacheKeyInput = String.format("%s%s%s", path, localizationId, localizationPath);
String cacheKey = UUID.nameUUIDFromBytes(cacheKeyInput.getBytes()).toString();
Cache<Object, Object> staticContentItemsCache = namedCacheProvider.getCache("staticContentItems");
StaticContentItem staticContentItem = (StaticContentItem)staticContentItemsCache.get(cacheKey);
if (staticContentItem == null) {
staticContentItem = processStaticContent(path, localizationId, localizationPath);
staticContentItemsCache.put(cacheKey, staticContentItem);
if (this.cacheStatisticsProvider != null) {
this.cacheStatisticsProvider.storeStatsInfo("staticContentItems", staticContentItem);
}
}
return staticContentItem;
}
}

public @NotNull StaticContentItem processStaticContent(String path, String localizationId, String localizationPath)
throws ContentProviderException {
StaticContentRequestDto requestDto = StaticContentRequestDto.builder(path, localizationId)
.localizationPath(localizationPath)
.baseUrl(webRequestContext.getBaseUrl())
.noMediaCache(isNoMediaCache(path, localizationPath))
.build();
StaticContentItem staticContentItem = staticContentResolver.getStaticContent(requestDto);
if (cacheStatisticsProvider != null) {
cacheStatisticsProvider.storeStatsInfo("staticContentItems", staticContentItem);
}
return staticContentItem;
return staticContentResolver.getStaticContent(requestDto);
}

protected PageModel loadPage(String path, Localization localization) throws ContentProviderException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void setup() {
graphQLProvider,
apiClientProvider,
cacheManager,
null,
cacheStatisticsProvider
));
}
Expand Down Expand Up @@ -103,7 +104,7 @@ public void getStaticContent() throws Exception {
when(staticContentResolver.getStaticContent(any(StaticContentRequestDto.class))).thenReturn(new StaticContentItem("testType",
contentFile, false));

StaticContentItem result = contentProvider.getStaticContent("/static", "localizationId", "localilzationPath");
StaticContentItem result = contentProvider.getStaticContent("/static", "localizationId", "localizationPath");

assertEquals("path", contentFile.getName());
assertEquals("testType", result.getContentType());
Expand Down
4 changes: 2 additions & 2 deletions dxa-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.sdl.dxa</groupId>
<artifactId>dxa-oss-parent</artifactId>
<version>2.3.5-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -201,7 +201,7 @@
<dependency>
<groupId>com.sdl.dxa</groupId>
<artifactId>dxa-oss-parent</artifactId>
<version>2.3.5-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down