Hi all, If we add a new experiment or make any cha...
# announcements
s
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
Depends on the SDK
s
I am using Java
f
we have streaming updates using server send events for some SDKs
s
is it supported for Java ?
f
@better-magician-65629 do you know?
s
I think its deprecated as per documentation @better-magician-65629 Please let me know if you have any other way
b
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
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
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
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
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
Yes, thanks !