/
refresh_policy.go
29 lines (26 loc) · 1.12 KB
/
refresh_policy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package configcat
// RefreshPolicy is the public interface of a refresh policy which's implementors should describe the configuration update rules.
type RefreshPolicy interface {
// GetConfigurationAsync reads the current configuration value.
GetConfigurationAsync() *AsyncResult
// RefreshAsync initiates a force refresh on the cached configuration.
RefreshAsync() *Async
// Close shuts down the policy.
Close()
}
// ConfigRefresher describes a configuration refresher, holds a shared implementation of the RefreshAsync method on RefreshPolicy.
type ConfigRefresher struct {
// The configuration provider implementation used to collect the latest configuration.
ConfigProvider ConfigProvider
// The configuration store used to maintain the cached configuration.
Store *ConfigStore
}
// RefreshAsync initiates a force refresh on the cached configuration.
func (refresher *ConfigRefresher) RefreshAsync() *Async {
return refresher.ConfigProvider.GetConfigurationAsync().Accept(func(result interface{}) {
response := result.(FetchResponse)
if result.(FetchResponse).IsFetched() {
refresher.Store.Set(response.Body)
}
})
}