https://www.growthbook.io/ logo
#announcements
Title
# announcements
s

square-restaurant-38765

07/19/2023, 4:12 PM
Hi all, If we add a new experiment or make any changes in current experiments in Growthbook then we need to again call the growthbook API in order to fetch the updated features json and then we can go on with any experiment. I was thinking of writing code in such a way that feature api is called only once the service starts so as to reduce the latency instead of calling it everytime a user enters the journey. But in order to get the updated feature json i need to call the API again right ? What should be the best way here to tackle this ?
1
f

fresh-football-47124

07/19/2023, 4:14 PM
Depends on the SDK
s

square-restaurant-38765

07/19/2023, 4:14 PM
I am using Java
f

fresh-football-47124

07/19/2023, 4:14 PM
we have streaming updates using server send events for some SDKs
s

square-restaurant-38765

07/19/2023, 4:14 PM
is it supported for Java ?
f

fresh-football-47124

07/19/2023, 4:16 PM
@better-magician-65629 do you know?
s

square-restaurant-38765

07/19/2023, 4:22 PM
I think its deprecated as per documentation @better-magician-65629 Please let me know if you have any other way
b

better-magician-65629

07/19/2023, 5:20 PM
we have an older set of webhooks that are deprecated. we have newer event webhooks that have superseded those, but the response returned is not suitable for working with the SDK. in the java SDK we have a class GBFeaturesRepository that should be created as a singleton and have its
initialize()
method called. example code: • java spring: https://github.com/growthbook/examples/tree/main/jvm-spring-web • kotlin ktor: https://github.com/growthbook/examples/tree/main/jvm-kotlin-ktor-example you can read about how to use the class here, and how the refreshing and cacheing logic works: https://docs.growthbook.io/lib/java#fetching-cacheing-and-refreshing-features-with-gbfeaturesrepository you can see the javadoc class docs here: https://growthbook.github.io/growthbook-sdk-java/growthbook/sdk/java/GBFeaturesRepository.html this should give you what you need to make requests and refresh features.
server-sent events are not supported in the java SDK currently.
s

square-restaurant-38765

07/19/2023, 6:58 PM
Thanks a lot Tina, will check this !!
If server-sent events are not supported then the above will not help since that also requires to make API call to refresh the features everytime.
b

better-magician-65629

07/19/2023, 7:16 PM
what's your currently configured
ttlSeconds
for the
GBFeaturesRepository
? if it's 0 then it'll go out every time, but that is not the default, the default is 60 seconds.
s

square-restaurant-38765

07/19/2023, 7:34 PM
Hey Tina,
GBFeaturesRepository
refreshes stale data every 60 seconds by making call to the Growthbook features endpoint right ? If yes, I asked if i can get the features value instead of making an API call everytime. Server sent events would be the perfect. But yes, instead of making feature API call for each users, i can make API call every 60 seconds to refresh data. This would help in someway. Thanks
b

better-magician-65629

07/19/2023, 7:36 PM
if you use the provided GBFeaturesRepository's default configuration, and you implement it as a singleton as recommended in the documentation, requests to the API will not happen more frequently than every 60 seconds. you can read the documentation linked above for more info, or see the examples linked above (each with a different style of implementation).
s

square-restaurant-38765

07/19/2023, 7:37 PM
Yes, thanks !
9 Views