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

Side by Side Diff: server/config/caching/proccache.go

Issue 2573403002: server/config: Generic caching backend. (Closed)
Patch Set: Created 4 years 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/server/config"
13
14 "golang.org/x/net/context"
15 )
16
17 // ProcCache returns a config.Backend that caches results in proccache.
iannucci 2017/01/07 20:53:17 results? resolves?
dnj 2017/01/10 03:29:17 Done.
18 //
19 // This will only cache results for AsService calls; any other Authority will
20 // pass through.
21 func ProcCache(b config.Backend, exp time.Duration) config.Backend {
22 return &Backend{
23 Backend: b,
24 CacheGet: func(c context.Context, key Key, l Loader) (*Value, er ror) {
25 if key.Authority != config.AsService {
26 return l(c, key, nil)
27 }
28
29 k := mkProcCacheKey(&key)
30 ret, err := proccache.GetOrMake(c, k, func() (interface{ }, time.Duration, error) {
31 v, err := l(c, key, nil)
32 if err != nil {
33 return nil, 0, err
34 }
35 return v, exp, nil
36 })
37 if err != nil {
38 return nil, err
39 }
40 return ret.(*Value), nil
41 },
42 }
43 }
44
45 type procCacheKey string
46
47 func mkProcCacheKey(key *Key) procCacheKey {
48 return procCacheKey(strings.Join([]string{
49 key.Schema,
50 string(key.Op),
51 key.ConfigSet,
52 key.Path,
53 string(key.GetAllType),
54 }, ":"))
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698