| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/binary" | 8 "encoding/binary" |
| 9 "sync" | 9 "sync" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 » "golang.org/x/net/context" | 12 » "github.com/luci/gae/service/info" |
| 13 » mc "github.com/luci/gae/service/memcache" |
| 13 | 14 |
| 14 mc "github.com/luci/gae/service/memcache" | |
| 15 "github.com/luci/luci-go/common/clock" | 15 "github.com/luci/luci-go/common/clock" |
| 16 "github.com/luci/luci-go/common/errors" | 16 "github.com/luci/luci-go/common/errors" |
| 17 |
| 18 "golang.org/x/net/context" |
| 17 ) | 19 ) |
| 18 | 20 |
| 19 type mcItem struct { | 21 type mcItem struct { |
| 20 key string | 22 key string |
| 21 value []byte | 23 value []byte |
| 22 flags uint32 | 24 flags uint32 |
| 23 expiration time.Duration | 25 expiration time.Duration |
| 24 | 26 |
| 25 CasID uint64 | 27 CasID uint64 |
| 26 } | 28 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 func useMC(c context.Context) context.Context { | 160 func useMC(c context.Context) context.Context { |
| 159 lck := sync.Mutex{} | 161 lck := sync.Mutex{} |
| 160 // TODO(riannucci): just use namespace for automatic key prefixing. Flus
h | 162 // TODO(riannucci): just use namespace for automatic key prefixing. Flus
h |
| 161 // actually wipes the ENTIRE memcache, regardless of namespace. | 163 // actually wipes the ENTIRE memcache, regardless of namespace. |
| 162 mcdMap := map[string]*memcacheData{} | 164 mcdMap := map[string]*memcacheData{} |
| 163 | 165 |
| 164 return mc.SetRawFactory(c, func(ic context.Context) mc.RawInterface { | 166 return mc.SetRawFactory(c, func(ic context.Context) mc.RawInterface { |
| 165 lck.Lock() | 167 lck.Lock() |
| 166 defer lck.Unlock() | 168 defer lck.Unlock() |
| 167 | 169 |
| 168 » » ns, _ := curGID(ic).getNamespace() | 170 » » ns := info.GetNamespace(ic) |
| 169 mcd, ok := mcdMap[ns] | 171 mcd, ok := mcdMap[ns] |
| 170 if !ok { | 172 if !ok { |
| 171 mcd = &memcacheData{items: map[string]*mcDataItem{}} | 173 mcd = &memcacheData{items: map[string]*mcDataItem{}} |
| 172 mcdMap[ns] = mcd | 174 mcdMap[ns] = mcd |
| 173 } | 175 } |
| 174 | 176 |
| 175 return &memcacheImpl{ | 177 return &memcacheImpl{ |
| 176 mcd, | 178 mcd, |
| 177 ic, | 179 ic, |
| 178 } | 180 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 return cur, nil | 344 return cur, nil |
| 343 } | 345 } |
| 344 | 346 |
| 345 func (m *memcacheImpl) Stats() (*mc.Statistics, error) { | 347 func (m *memcacheImpl) Stats() (*mc.Statistics, error) { |
| 346 m.data.lock.RLock() | 348 m.data.lock.RLock() |
| 347 defer m.data.lock.RUnlock() | 349 defer m.data.lock.RUnlock() |
| 348 | 350 |
| 349 ret := m.data.stats | 351 ret := m.data.stats |
| 350 return &ret, nil | 352 return &ret, nil |
| 351 } | 353 } |
| OLD | NEW |