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

Side by Side Diff: appengine/gaeauth/server/cache.go

Issue 2646733008: server/auth: Add in-process LRU-based cache. (Closed)
Patch Set: Rename GlobalCache => Cache, ProcCache => MemoryCache. 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
« no previous file with comments | « no previous file | appengine/gaemiddleware/context.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package server 5 package server
6 6
7 import ( 7 import (
8 "time" 8 "time"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 11
12 "github.com/luci/gae/service/info" 12 "github.com/luci/gae/service/info"
13 mc "github.com/luci/gae/service/memcache" 13 mc "github.com/luci/gae/service/memcache"
14 14
15 "github.com/luci/luci-go/common/errors" 15 "github.com/luci/luci-go/common/errors"
16 "github.com/luci/luci-go/server/auth" 16 "github.com/luci/luci-go/server/auth"
17 ) 17 )
18 18
19 // Memcache implements auth.GlobalCache on top of GAE memcache. 19 // Memcache implements auth.Cache on top of GAE memcache.
20 type Memcache struct { 20 type Memcache struct {
21 Namespace string 21 Namespace string
22 } 22 }
23 23
24 var _ auth.GlobalCache = (*Memcache)(nil) 24 var _ auth.Cache = (*Memcache)(nil)
25 25
26 // Get returns a cached item or (nil, nil) if it's not in the cache. 26 // Get returns a cached item or (nil, nil) if it's not in the cache.
27 // 27 //
28 // Any returned error is transient error. 28 // Any returned error is transient error.
29 func (m *Memcache) Get(c context.Context, key string) ([]byte, error) { 29 func (m *Memcache) Get(c context.Context, key string) ([]byte, error) {
30 c = m.cacheContext(c) 30 c = m.cacheContext(c)
31 31
32 switch itm, err := mc.GetKey(c, key); { 32 switch itm, err := mc.GetKey(c, key); {
33 case err == mc.ErrCacheMiss: 33 case err == mc.ErrCacheMiss:
34 return nil, nil 34 return nil, nil
(...skipping 16 matching lines...) Expand all
51 if err := mc.Set(c, item); err != nil { 51 if err := mc.Set(c, item); err != nil {
52 return errors.WrapTransient(err) 52 return errors.WrapTransient(err)
53 } 53 }
54 return nil 54 return nil
55 } 55 }
56 56
57 // cache returns properly namespaced memcache.Interface. 57 // cache returns properly namespaced memcache.Interface.
58 func (m *Memcache) cacheContext(c context.Context) context.Context { 58 func (m *Memcache) cacheContext(c context.Context) context.Context {
59 return info.MustNamespace(c, m.Namespace) 59 return info.MustNamespace(c, m.Namespace)
60 } 60 }
OLDNEW
« no previous file with comments | « no previous file | appengine/gaemiddleware/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698