Skip to content

Commit bbca0cc

Browse files
authored
Use built in client http caching (#129)
* Use built in client http caching * Use LRU cache implementation; set some defaults and config * Use human readable cache sizes
1 parent 2c872f6 commit bbca0cc

13 files changed

Lines changed: 1387 additions & 33 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*.iws
66

77
build/
8+
config/bulldozer.yml

Gopkg.lock

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bulldozer.example.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ logging:
1414
# Choose from: debug, info, warn, error
1515
level: debug
1616

17+
# Options for the HTTP Cache
18+
cache:
19+
# The maximum size of the cache (specified in human readable units)
20+
max_size: 50 MB
21+
1722
# Options for connecting to GitHub
1823
github:
1924
# The URL of the GitHub homepage

server/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package server
1616

1717
import (
18+
"github.com/c2h5oh/datasize"
1819
"github.com/palantir/go-baseapp/baseapp"
1920
"github.com/palantir/go-baseapp/baseapp/datadog"
2021
"github.com/palantir/go-githubapp/githubapp"
@@ -35,13 +36,18 @@ type Config struct {
3536
Options Options `yaml:"options"`
3637
Logging LoggingConfig `yaml:"logging"`
3738
Datadog datadog.Config `yaml:"datadog"`
39+
Cache CacheConfig `yaml:"cache"`
3840
}
3941

4042
type LoggingConfig struct {
4143
Level string `yaml:"level"`
4244
Text bool `yaml:"text"`
4345
}
4446

47+
type CacheConfig struct {
48+
MaxSize datasize.ByteSize `yaml:"max_size"`
49+
}
50+
4551
type Options struct {
4652
AppName string `yaml:"app_name"`
4753
ConfigurationPath string `yaml:"configuration_path"`

server/server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package server
1717
import (
1818
"fmt"
1919

20+
"github.com/c2h5oh/datasize"
21+
"github.com/die-net/lrucache"
22+
"github.com/gregjones/httpcache"
2023
"github.com/palantir/go-baseapp/baseapp"
2124
"github.com/palantir/go-baseapp/baseapp/datadog"
2225
"github.com/palantir/go-githubapp/githubapp"
@@ -48,10 +51,16 @@ func New(c *Config) (*Server, error) {
4851
return nil, errors.Wrap(err, "failed to initialize base server")
4952
}
5053

54+
maxSize := int64(50 * datasize.MB)
55+
if c.Cache.MaxSize != 0 {
56+
maxSize = int64(c.Cache.MaxSize)
57+
}
58+
5159
userAgent := fmt.Sprintf("%s/%s", c.Options.AppName, version.GetVersion())
5260
clientCreator, err := githubapp.NewDefaultCachingClientCreator(
5361
c.Github,
5462
githubapp.WithClientUserAgent(userAgent),
63+
githubapp.WithClientCaching(true, func() httpcache.Cache { return lrucache.New(maxSize, 0) }),
5564
githubapp.WithClientMiddleware(
5665
githubapp.ClientLogging(zerolog.DebugLevel),
5766
githubapp.ClientMetrics(base.Registry()),

vendor/github.com/c2h5oh/datasize/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/c2h5oh/datasize/datasize.go

Lines changed: 217 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)