/
refresh_policy.go
39 lines (35 loc) · 1.43 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
30
31
32
33
34
35
36
37
38
39
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.
configFetcher configProvider
// The configuration store used to maintain the cached configuration.
store *configStore
// The logger instance.
logger Logger
}
// RefreshMode is a base for refresh mode configurations.
type RefreshMode interface {
// Returns the identifier sent in User-Agent by the config fetcher.
getModeIdentifier() string
// Creates a refresh policy from refresh mode.
accept(visitor pollingModeVisitor) refreshPolicy
}
// refreshAsync initiates a force refresh on the cached configuration.
func (refresher *configRefresher) refreshAsync() *async {
return refresher.configFetcher.getConfigurationAsync().accept(func(result interface{}) {
response := result.(fetchResponse)
if result.(fetchResponse).isFetched() {
refresher.store.set(response.body)
}
})
}