helpful-traffic-38691
03/27/2023, 9:58 AMbetter-magician-65629
03/28/2023, 12:53 AMGBFeaturesRepository class that does networking for you, it'll re-fetch the features based on the criteria described here: https://docs.growthbook.io/lib/java#fetching-cacheing-and-refreshing-features-with-gbfeaturesrepository
Provided that your instance of GBContext has the latest features, the feature will be evaluated based on the updates you made:
// Initialize the GrowthBook SDK with the GBContext and features
GBContext context = GBContext
.builder()
.featuresJson(featuresRepository.getFeaturesJson())
.attributesJson(userAttributesJson)
.build();
if you aren't using the GBFeaturesRepository to manage features, you'll need to fetch the features yourself and set them on the GBContext manually. you can use the builder meethod .featuresJson() when creating the context or the setFeaturesJson() method after the context is already created. Docs: https://growthbook.github.io/growthbook-sdk-java/growthbook/sdk/java/GBContext.html
Let me know if you had any other questions.better-magician-65629
03/28/2023, 12:55 AMhelpful-traffic-38691
03/28/2023, 1:16 PMGBFeaturesRepository
.builder() .endpoint("<https://cdn.growthbook.io/api/features/sdk-key>").ttlSeconds(300) .build();
This ttl second set here is not working. Features are not getting refreshed.
Please let me know if I miss anythingbetter-magician-65629
03/28/2023, 5:39 PMbetter-magician-65629
03/28/2023, 5:41 PM/di endpoint in the java spring example. https://github.com/growthbook/examples/blob/main/jvm-spring-web/src/main/java/com/example/demo/MainController.java#L288helpful-traffic-38691
04/10/2023, 12:41 PMbetter-magician-65629
04/12/2023, 5:32 PMbetter-magician-65629
04/12/2023, 5:36 PM// Initialize the GrowthBook SDK with the GBContext and features
GBContext context = GBContext
.builder()
.featuresJson(featuresRepository.getFeaturesJson()) // This needs to be called every time
.attributesJson(userAttributesJson) // the new user needs to be added to the context every time
.build();
as mentioned, the refreshing uses a stale-while-revalidate approach. so the first call to stale features will return the stale features but refresh them for subsequent calls.