Skip to content
Snippets Groups Projects
Verified Commit 5ab46240 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Implemented optional caches

parent 2d8ea3f8
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,8 @@ type EndpointConfig struct { ...@@ -16,8 +16,8 @@ type EndpointConfig struct {
} }
type CacheConfig struct { type CacheConfig struct {
Redis RedisCacheConfig `yaml:"redis"` Redis *RedisCacheConfig `yaml:"redis"`
Memory MemoryCacheConfig `yaml:"memory"` Memory *MemoryCacheConfig `yaml:"memory"`
} }
type RedisCacheConfig struct { type RedisCacheConfig struct {
......
...@@ -56,6 +56,18 @@ func main() { ...@@ -56,6 +56,18 @@ func main() {
autocompleteStations := loadAutocompleteStations() autocompleteStations := loadAutocompleteStations()
var caches []bahn.CacheBackend
if config.Caches.Memory != nil {
caches = append(caches, NewMemoryCache(config.Caches.Memory.Timeout))
}
if config.Caches.Redis != nil {
caches = append(caches, NewRedisCache(
config.Caches.Redis.Address,
config.Caches.Redis.Password,
config.Caches.Redis.Timeout,
))
}
apiClient := bahn.ApiClient{ apiClient := bahn.ApiClient{
IrisBaseUrl: config.Endpoints.Iris, IrisBaseUrl: config.Endpoints.Iris,
CoachSequenceBaseUrl: config.Endpoints.CoachSequence, CoachSequenceBaseUrl: config.Endpoints.CoachSequence,
...@@ -63,14 +75,7 @@ func main() { ...@@ -63,14 +75,7 @@ func main() {
HttpClient: &http.Client{ HttpClient: &http.Client{
Timeout: config.RequestTimeout, Timeout: config.RequestTimeout,
}, },
Caches: []bahn.CacheBackend{ Caches: caches,
NewMemoryCache(config.Caches.Memory.Timeout),
NewRedisCache(
config.Caches.Redis.Address,
config.Caches.Redis.Password,
config.Caches.Redis.Timeout,
),
},
} }
http.HandleFunc("/autocomplete/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/autocomplete/", func(w http.ResponseWriter, r *http.Request) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment