Chromium Code Reviews| Index: logdog/server/service/config/opts.go |
| diff --git a/logdog/server/service/config/opts.go b/logdog/server/service/config/opts.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1ac0863f6fff7dd6eecde38a4c7f1927805b9aec |
| --- /dev/null |
| +++ b/logdog/server/service/config/opts.go |
| @@ -0,0 +1,36 @@ |
| +// Copyright 2017 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package config |
| + |
| +import ( |
| + "time" |
| + |
| + "github.com/luci/luci-go/luci_config/server/cfgclient/backend" |
| + "github.com/luci/luci-go/luci_config/server/cfgclient/backend/caching" |
| + |
| + "golang.org/x/net/context" |
| +) |
| + |
| +// CacheOptions is the set of configuration options. |
| +type CacheOptions struct { |
| + // CacheExpiration is the amount of time that a config entry should be cached. |
| + CacheExpiration time.Duration |
|
iannucci
2017/01/21 00:23:13
a negative (or 0?) value has no effect
dnj
2017/01/21 01:37:31
Done.
|
| +} |
| + |
| +// WrapBackend wraps the supplied backend with caching as appropriately |
| +// configured. |
|
iannucci
2017/01/21 00:23:13
Maybe:
WrapBackend updates the context with a n
dnj
2017/01/21 01:37:31
Done.
|
| +func (o *CacheOptions) WrapBackend(c context.Context, base backend.B) context.Context { |
| + return backend.WithFactory(c, func(c context.Context) backend.B { |
| + // Start with our base Backend. |
| + be := base |
| + |
| + // Add a proccache-based config cache. |
| + if o.CacheExpiration > 0 { |
|
iannucci
2017/01/21 00:23:13
== 0 could be problematic... I'd skip proccache in
dnj
2017/01/21 01:37:31
Done.
|
| + be = caching.ProcCache(be, o.CacheExpiration) |
| + } |
| + |
| + return be |
| + }) |
| +} |