Skip to content

Commit

Permalink
Use built in client http caching (#129)
Browse files Browse the repository at this point in the history
* Use built in client http caching

* Use LRU cache implementation; set some defaults and config

* Use human readable cache sizes
  • Loading branch information
asvoboda authored Jun 24, 2019
1 parent 2c872f6 commit bbca0cc
Show file tree
Hide file tree
Showing 13 changed files with 1,387 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.iws

build/
config/bulldozer.yml
31 changes: 29 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/bulldozer.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ logging:
# Choose from: debug, info, warn, error
level: debug

# Options for the HTTP Cache
cache:
# The maximum size of the cache (specified in human readable units)
max_size: 50 MB

# Options for connecting to GitHub
github:
# The URL of the GitHub homepage
Expand Down
6 changes: 6 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package server

import (
"github.com/c2h5oh/datasize"
"github.com/palantir/go-baseapp/baseapp"
"github.com/palantir/go-baseapp/baseapp/datadog"
"github.com/palantir/go-githubapp/githubapp"
Expand All @@ -35,13 +36,18 @@ type Config struct {
Options Options `yaml:"options"`
Logging LoggingConfig `yaml:"logging"`
Datadog datadog.Config `yaml:"datadog"`
Cache CacheConfig `yaml:"cache"`
}

type LoggingConfig struct {
Level string `yaml:"level"`
Text bool `yaml:"text"`
}

type CacheConfig struct {
MaxSize datasize.ByteSize `yaml:"max_size"`
}

type Options struct {
AppName string `yaml:"app_name"`
ConfigurationPath string `yaml:"configuration_path"`
Expand Down
9 changes: 9 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package server
import (
"fmt"

"github.com/c2h5oh/datasize"
"github.com/die-net/lrucache"
"github.com/gregjones/httpcache"
"github.com/palantir/go-baseapp/baseapp"
"github.com/palantir/go-baseapp/baseapp/datadog"
"github.com/palantir/go-githubapp/githubapp"
Expand Down Expand Up @@ -48,10 +51,16 @@ func New(c *Config) (*Server, error) {
return nil, errors.Wrap(err, "failed to initialize base server")
}

maxSize := int64(50 * datasize.MB)
if c.Cache.MaxSize != 0 {
maxSize = int64(c.Cache.MaxSize)
}

userAgent := fmt.Sprintf("%s/%s", c.Options.AppName, version.GetVersion())
clientCreator, err := githubapp.NewDefaultCachingClientCreator(
c.Github,
githubapp.WithClientUserAgent(userAgent),
githubapp.WithClientCaching(true, func() httpcache.Cache { return lrucache.New(maxSize, 0) }),
githubapp.WithClientMiddleware(
githubapp.ClientLogging(zerolog.DebugLevel),
githubapp.ClientMetrics(base.Registry()),
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/c2h5oh/datasize/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

217 changes: 217 additions & 0 deletions vendor/github.com/c2h5oh/datasize/datasize.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bbca0cc

Please sign in to comment.