OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "infra/gae/libs/wrapper" | 8 "infra/gae/libs/wrapper" |
9 "infra/gae/libs/wrapper/gae/commonErrors" | 9 "infra/gae/libs/wrapper/gae/commonErrors" |
10 "infra/gae/libs/wrapper/unsafe" | 10 "infra/gae/libs/wrapper/unsafe" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 data *memcacheData | 33 data *memcacheData |
34 timeNow func() time.Time | 34 timeNow func() time.Time |
35 } | 35 } |
36 | 36 |
37 var ( | 37 var ( |
38 _ = wrapper.Memcache((*memcacheImpl)(nil)) | 38 _ = wrapper.Memcache((*memcacheImpl)(nil)) |
39 _ = wrapper.Testable((*memcacheImpl)(nil)) | 39 _ = wrapper.Testable((*memcacheImpl)(nil)) |
40 ) | 40 ) |
41 | 41 |
42 // UseMC adds a wrapper.Memcache implementation to context, accessible | 42 // useMC adds a wrapper.Memcache implementation to context, accessible |
43 // by wrapper.GetMC(c) | 43 // by wrapper.GetMC(c) |
44 func UseMC(c context.Context) context.Context { | 44 func useMC(c context.Context) context.Context { |
45 lck := sync.Mutex{} | 45 lck := sync.Mutex{} |
46 mcdMap := map[string]*memcacheData{} | 46 mcdMap := map[string]*memcacheData{} |
47 | 47 |
48 return wrapper.SetMCFactory(c, func(ic context.Context) wrapper.Memcache
{ | 48 return wrapper.SetMCFactory(c, func(ic context.Context) wrapper.Memcache
{ |
49 lck.Lock() | 49 lck.Lock() |
50 defer lck.Unlock() | 50 defer lck.Unlock() |
51 | 51 |
52 ns := curGID(ic).namespace | 52 ns := curGID(ic).namespace |
53 mcd, ok := mcdMap[ns] | 53 mcd, ok := mcdMap[ns] |
54 if !ok { | 54 if !ok { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 m.data.lock.Lock() | 178 m.data.lock.Lock() |
179 defer m.data.lock.Unlock() | 179 defer m.data.lock.Unlock() |
180 | 180 |
181 if _, ok := m.retrieve(key); ok { | 181 if _, ok := m.retrieve(key); ok { |
182 delete(m.data.items, key) | 182 delete(m.data.items, key) |
183 return nil | 183 return nil |
184 } | 184 } |
185 return memcache.ErrCacheMiss | 185 return memcache.ErrCacheMiss |
186 } | 186 } |
OLD | NEW |