Skip to content

Commit f58a60f

Browse files
authored
Apply caching middleware for token client (#57)
1 parent d8a2c92 commit f58a60f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

githubapp/client_creator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,20 @@ func (c *clientCreator) NewInstallationV4Client(installationID int64) (*githubv4
249249
func (c *clientCreator) NewTokenClient(token string) (*github.Client, error) {
250250
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
251251
tc := oauth2.NewClient(context.Background(), ts)
252-
return c.newClient(tc, nil, "oauth token", 0)
252+
253+
middleware := []ClientMiddleware{}
254+
if c.cacheFunc != nil {
255+
middleware = append(middleware, cache(c.cacheFunc), cacheControl(c.alwaysValidate))
256+
}
257+
258+
return c.newClient(tc, middleware, "oauth token", 0)
253259
}
254260

255261
func (c *clientCreator) NewTokenV4Client(token string) (*githubv4.Client, error) {
256262
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
257263
tc := oauth2.NewClient(context.Background(), ts)
264+
// The v4 API primarily uses POST requests (except for introspection queries)
265+
// which we cannot cache, so don't construct the middleware
258266
return c.newV4Client(tc, nil, "oauth token")
259267
}
260268

0 commit comments

Comments
 (0)