33import com .sdl .dxa .api .datamodel .model .ContentModelData ;
44import com .sdl .dxa .api .datamodel .model .EntityModelData ;
55import com .sdl .dxa .api .datamodel .model .PageModelData ;
6+ import com .sdl .dxa .caching .NamedCacheProvider ;
67import com .sdl .dxa .caching .statistics .CacheStatisticsProvider ;
78import com .sdl .dxa .common .dto .EntityRequestDto ;
89import com .sdl .dxa .common .dto .PageRequestDto ;
4445import org .springframework .web .context .request .RequestContextHolder ;
4546
4647import jakarta .servlet .http .HttpSession ;
48+
49+ import javax .cache .Cache ;
4750import java .io .Serializable ;
4851import java .util .HashMap ;
4952import java .util .List ;
5053import java .util .Map ;
54+ import java .util .UUID ;
5155import java .util .stream .Collectors ;
5256
5357/**
@@ -65,6 +69,7 @@ public class GraphQLContentProvider extends AbstractContentProvider implements C
6569 private final WebRequestContext webRequestContext ;
6670 private ApiClientProvider pcaClientProvider ;
6771 private CacheManager cacheManager ;
72+ private NamedCacheProvider namedCacheProvider ;
6873 private CacheStatisticsProvider cacheStatisticsProvider ;
6974
7075 @ Autowired
@@ -73,6 +78,7 @@ public GraphQLContentProvider(WebRequestContext webRequestContext,
7378 ModelBuilderPipeline builderPipeline , GraphQLProvider graphQLProvider ,
7479 ApiClientProvider pcaClientProvider ,
7580 @ Qualifier ("compositeCacheManager" ) CacheManager cacheManager ,
81+ NamedCacheProvider namedCacheProvider ,
7682 CacheStatisticsProvider cacheStatisticsProvider ) {
7783 super (webRequestContext , cacheManager );
7884 this .webRequestContext = webRequestContext ;
@@ -81,6 +87,7 @@ public GraphQLContentProvider(WebRequestContext webRequestContext,
8187 this .staticContentResolver = staticContentResolver ;
8288 this .builderPipeline = builderPipeline ;
8389 this .graphQLProvider = graphQLProvider ;
90+ this .namedCacheProvider = namedCacheProvider ;
8491 this .cacheStatisticsProvider = cacheStatisticsProvider ;
8592 }
8693
@@ -160,23 +167,36 @@ private boolean isNoMediaCache(String path, String localizationPath) {
160167 return !FileUtils .isEssentialConfiguration (path , localizationPath ) && webRequestContext .isSessionPreview ();
161168 }
162169
163- /**
164- * {@inheritDoc}
165- *
166- */
167170 @ Override
168171 public @ NotNull StaticContentItem getStaticContent (String path , String localizationId , String localizationPath )
169172 throws ContentProviderException {
173+ if (namedCacheProvider == null || !namedCacheProvider .isCacheEnabled ("staticContentItems" )) {
174+ return processStaticContent (path , localizationId , localizationPath );
175+ }
176+ else {
177+ String cacheKeyInput = String .format ("%s%s%s" , path , localizationId , localizationPath );
178+ String cacheKey = UUID .nameUUIDFromBytes (cacheKeyInput .getBytes ()).toString ();
179+ Cache <Object , Object > staticContentItemsCache = namedCacheProvider .getCache ("staticContentItems" );
180+ StaticContentItem staticContentItem = (StaticContentItem )staticContentItemsCache .get (cacheKey );
181+ if (staticContentItem == null ) {
182+ staticContentItem = processStaticContent (path , localizationId , localizationPath );
183+ staticContentItemsCache .put (cacheKey , staticContentItem );
184+ if (this .cacheStatisticsProvider != null ) {
185+ this .cacheStatisticsProvider .storeStatsInfo ("staticContentItems" , staticContentItem );
186+ }
187+ }
188+ return staticContentItem ;
189+ }
190+ }
191+
192+ public @ NotNull StaticContentItem processStaticContent (String path , String localizationId , String localizationPath )
193+ throws ContentProviderException {
170194 StaticContentRequestDto requestDto = StaticContentRequestDto .builder (path , localizationId )
171195 .localizationPath (localizationPath )
172196 .baseUrl (webRequestContext .getBaseUrl ())
173197 .noMediaCache (isNoMediaCache (path , localizationPath ))
174198 .build ();
175- StaticContentItem staticContentItem = staticContentResolver .getStaticContent (requestDto );
176- if (cacheStatisticsProvider != null ) {
177- cacheStatisticsProvider .storeStatsInfo ("staticContentItems" , staticContentItem );
178- }
179- return staticContentItem ;
199+ return staticContentResolver .getStaticContent (requestDto );
180200 }
181201
182202 protected PageModel loadPage (String path , Localization localization ) throws ContentProviderException {
0 commit comments