-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from configcat/data-governance
- Loading branch information
Showing
25 changed files
with
585 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ go: | |
- master | ||
|
||
before_script: | ||
- cd v5 | ||
- cd v6 | ||
- go vet ./... | ||
|
||
script: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,29 @@ | ||
package configcat | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// ConfigCache is a cache API used to make custom cache implementations. | ||
type ConfigCache interface { | ||
// get reads the configuration from the cache. | ||
Get() (string, error) | ||
Get(key string) (string, error) | ||
// set writes the configuration into the cache. | ||
Set(value string) error | ||
Set(key string, value string) error | ||
} | ||
|
||
type inMemoryConfigCache struct { | ||
value string | ||
} | ||
|
||
// configStore is used to maintain the cached configuration. | ||
type configStore struct { | ||
cache ConfigCache | ||
logger Logger | ||
inMemoryValue string | ||
sync.RWMutex | ||
} | ||
|
||
func newConfigStore(log Logger, cache ConfigCache) *configStore { | ||
return &configStore{cache: cache, logger: log} | ||
store map[string]string | ||
} | ||
|
||
// newInMemoryConfigCache creates an in-memory cache implementation used to store the fetched configurations. | ||
func newInMemoryConfigCache() *inMemoryConfigCache { | ||
return &inMemoryConfigCache{value: ""} | ||
return &inMemoryConfigCache{store: make(map[string]string)} | ||
} | ||
|
||
// get reads the configuration from the cache. | ||
func (cache *inMemoryConfigCache) Get() (string, error) { | ||
return cache.value, nil | ||
func (cache *inMemoryConfigCache) Get(key string) (string, error) { | ||
return cache.store[key], nil | ||
} | ||
|
||
// set writes the configuration into the cache. | ||
func (cache *inMemoryConfigCache) Set(value string) error { | ||
cache.value = value | ||
func (cache *inMemoryConfigCache) Set(key string, value string) error { | ||
cache.store[key] = value | ||
return nil | ||
} | ||
|
||
// get reads the configuration. | ||
func (store *configStore) get() string { | ||
store.RLock() | ||
defer store.RUnlock() | ||
value, err := store.cache.Get() | ||
if err != nil { | ||
store.logger.Errorf("Reading from the cache failed, %s", err) | ||
return store.inMemoryValue | ||
} | ||
|
||
return value | ||
} | ||
|
||
// set writes the configuration. | ||
func (store *configStore) set(value string) { | ||
store.Lock() | ||
defer store.Unlock() | ||
store.inMemoryValue = value | ||
err := store.cache.Set(value) | ||
if err != nil { | ||
store.logger.Errorf("Saving into the cache failed, %s", err) | ||
} | ||
} |
Oops, something went wrong.