diff --git a/github/github.go b/github/github.go index 89a49913..146130d9 100644 --- a/github/github.go +++ b/github/github.go @@ -13,6 +13,7 @@ import ( "github.com/actions-runner-controller/actions-runner-controller/github/metrics" "github.com/bradleyfalzon/ghinstallation" "github.com/google/go-github/v39/github" + "github.com/gregjones/httpcache" "golang.org/x/oauth2" ) @@ -82,8 +83,10 @@ func (c *Config) NewClient() (*Client, error) { transport = tr } - transport = metrics.Transport{Transport: transport} - httpClient := &http.Client{Transport: transport} + cached := httpcache.NewTransport(httpcache.NewMemoryCache()) + cached.Transport = transport + metricsTransport := metrics.Transport{Transport: cached} + httpClient := &http.Client{Transport: metricsTransport} var client *github.Client var githubBaseURL string diff --git a/go.mod b/go.mod index f9627220..25380078 100644 --- a/go.mod +++ b/go.mod @@ -41,6 +41,7 @@ require ( github.com/google/gofuzz v1.1.0 // indirect github.com/google/uuid v1.1.2 // indirect github.com/googleapis/gnostic v0.5.5 // indirect + github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect diff --git a/go.sum b/go.sum index d9d4388c..65d55022 100644 --- a/go.sum +++ b/go.sum @@ -259,6 +259,8 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA= +github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=