From e5314fd75d63d56911769f636fdd1d91bfbfaff3 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sun, 4 Apr 2021 00:22:35 +0200 Subject: Added 60 seconds caching to navitia api departures requests --- navitia_api_client/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'navitia_api_client/client.go') diff --git a/navitia_api_client/client.go b/navitia_api_client/client.go index d08ca19..aef8d0e 100644 --- a/navitia_api_client/client.go +++ b/navitia_api_client/client.go @@ -3,12 +3,21 @@ package navitia_api_client import ( "fmt" "net/http" + "sync" "time" ) type Client struct { baseURL string httpClient *http.Client + + mutex sync.Mutex + cache map[string]cachedResult +} + +type cachedResult struct { + ts time.Time + result interface{} } func NewClient(token string) *Client { @@ -17,5 +26,6 @@ func NewClient(token string) *Client { httpClient: &http.Client{ Timeout: time.Minute, }, + cache: make(map[string]cachedResult), } } -- cgit v1.2.3