| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package config |
| 6 |
| 7 import ( |
| 8 "time" |
| 9 |
| 10 "github.com/luci/luci-go/luci_config/server/cfgclient/backend" |
| 11 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/caching" |
| 12 |
| 13 "golang.org/x/net/context" |
| 14 ) |
| 15 |
| 16 // CacheOptions is the set of configuration options. |
| 17 type CacheOptions struct { |
| 18 // CacheExpiration is the amount of time that a config entry should be c
ached. |
| 19 // |
| 20 // If this value is <= 0, no configuration caching will be enabled. This |
| 21 // should not be set for production systems. |
| 22 CacheExpiration time.Duration |
| 23 } |
| 24 |
| 25 // WrapBackend wraps the supplied base backend in caching layers and returns a |
| 26 // Conext with the resulting backend installed. |
| 27 func (o *CacheOptions) WrapBackend(c context.Context, base backend.B) context.Co
ntext { |
| 28 return backend.WithFactory(c, func(c context.Context) backend.B { |
| 29 // Start with our base Backend. |
| 30 be := base |
| 31 |
| 32 // Add a proccache-based config cache. |
| 33 if o.CacheExpiration > 0 { |
| 34 be = caching.ProcCache(be, o.CacheExpiration) |
| 35 } |
| 36 |
| 37 return be |
| 38 }) |
| 39 } |
| OLD | NEW |