Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Header/Footer from external service

Avatar

Level 1

Hi Everyone - I have a requirement to consume header/footer hosted on our react application. React team has built an endpoint for both header and footer which when called return complete html ( including js and css references). I was planning to build a simple header and footer component and through SlingModel call these two endpoints and include api response. These components will then be included in experience fragments and will be part of editable templates. 

My concern/question is will there be call to SlingModel ( which in turn will make an http call to react api's) for every page built using editable template? If yes, how can i limit backend API calls to just one time and then use the response for all the pages?

 

Thanks in advance.

 

~Pragya

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @praja1987,

Please check this Sling Model Caching, it may helps you to avoid multiple invocation.

https://sling.apache.org/documentation/bundles/models.html#caching

You only have to specify cache=true in the Model-annotation.

@Model(adaptable = SlingHttpServletRequest.class, cache = true)
public class ModelClass {
   ...
}  

Regards,

Santosh 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @praja1987,

Please check this Sling Model Caching, it may helps you to avoid multiple invocation.

https://sling.apache.org/documentation/bundles/models.html#caching

You only have to specify cache=true in the Model-annotation.

@Model(adaptable = SlingHttpServletRequest.class, cache = true)
public class ModelClass {
   ...
}  

Regards,

Santosh