Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: luci_config/server/cfgclient/backend/caching/proccache.go

Issue 2573403002: server/config: Generic caching backend. (Closed)
Patch Set: Updated interface, rebased Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 caching
6
7 import (
8 "strings"
9 "time"
10
11 "github.com/luci/luci-go/common/data/caching/proccache"
12 "github.com/luci/luci-go/luci_config/server/cfgclient/backend"
13
14 "golang.org/x/net/context"
15 )
16
17 // ProcCache returns a backend.B that caches configuration service results in an
18 // in-memory proccache instance.
19 //
20 // This will only cache results for AsService calls; any other Authority will
21 // pass through.
22 func ProcCache(b backend.B, exp time.Duration) backend.B {
23 return &Backend{
24 B: b,
25 CacheGet: func(c context.Context, key Key, l Loader) (*Value, er ror) {
26 if key.Authority != backend.AsService {
27 return l(c, key, nil)
28 }
29
30 k := mkProcCacheKey(&key)
31 ret, err := proccache.GetOrMake(c, k, func() (interface{ }, time.Duration, error) {
32 v, err := l(c, key, nil)
33 if err != nil {
34 return nil, 0, err
35 }
36 return v, exp, nil
37 })
38 if err != nil {
39 return nil, err
40 }
41 return ret.(*Value), nil
42 },
43 }
44 }
45
46 type procCacheKey string
47
48 func mkProcCacheKey(key *Key) procCacheKey {
49 return procCacheKey(strings.Join([]string{
50 key.Schema,
51 string(key.Op),
52 key.ConfigSet,
53 key.Path,
54 string(key.GetAllTarget),
55 }, ":"))
56 }
OLDNEW
« no previous file with comments | « luci_config/server/cfgclient/backend/caching/doc.go ('k') | luci_config/server/cfgclient/backend/caching/proccache_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698