bazel-remote
bazel-remote copied to clipboard
Usage as library
It would be great if we could add a way to use this cache as a library (i.e. to make integration into existing projects easier). As a side effect, this would mostly implement #12, except the configuration part, and make it easier for folks to implement their own storage mechanism on top of GCS, S3, ...
We would create a new package httpcache (to avoid conflicts with net/http), which has a function New that returns a http.Handler.
type Options struct {
// Logging, ...
}
// New creates a new Bazel cache which uses the provided StorageMechanism
// to store and retrieve cached files.
func New(StorageMechanism, Options) http.Handler {
// ...
}
(I think StorageMechanism will look mostly like LRU @nicolov implemented recently).
WDYT?
Yes, this was the idea that I had in mind when refactoring the code, but I didn't want to make too many changes at the same time (and didn't have an immediate use case for multiple backends).
I'll just inject NewHTTPCache with a Cache instead of the cacheDir, maxSize arguments, and you should be good to go, right?
I‘m not completely sure that this would be sufficient. httpCache seems to have a very tight coupling to the stats, which might cause issues in alternative implementations of Cache (I only have an immediate use case for alternative stogage).
I guess it‘s the best if I investigate some possible solutions and then report the results here.
I have pushed a change that goes into this direction https://github.com/buchgr/bazel-remote/commit/700d941c1a083f87e2b11d4437bf28f931e454f7
sorry for the large commit :(