| 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 dscache | 5 package dscache |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "math/rand" | 9 "math/rand" |
| 10 "time" | 10 "time" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 if ret > MaxShards { | 36 if ret > MaxShards { |
| 37 ret = MaxShards | 37 ret = MaxShards |
| 38 } | 38 } |
| 39 return ret | 39 return ret |
| 40 } | 40 } |
| 41 | 41 |
| 42 func (s *supportContext) mkRandKeys(keys []*ds.Key, metas ds.MultiMetaGetter) []
string { | 42 func (s *supportContext) mkRandKeys(keys []*ds.Key, metas ds.MultiMetaGetter) []
string { |
| 43 ret := []string(nil) | 43 ret := []string(nil) |
| 44 for i, key := range keys { | 44 for i, key := range keys { |
| 45 » » if !metas.GetMetaDefault(i, CacheEnableMeta, true).(bool) { | 45 » » mg := metas.GetSingle(i) |
| 46 » » if !ds.GetMetaDefault(mg, CacheEnableMeta, true).(bool) { |
| 46 continue | 47 continue |
| 47 } | 48 } |
| 48 shards := s.numShards(key) | 49 shards := s.numShards(key) |
| 49 if shards == 0 { | 50 if shards == 0 { |
| 50 continue | 51 continue |
| 51 } | 52 } |
| 52 if ret == nil { | 53 if ret == nil { |
| 53 ret = make([]string, len(keys)) | 54 ret = make([]string, len(keys)) |
| 54 } | 55 } |
| 55 ret[i] = MakeMemcacheKey(s.mr.Intn(shards), key) | 56 ret[i] = MakeMemcacheKey(s.mr.Intn(shards), key) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return nil, nil | 150 return nil, nil |
| 150 } | 151 } |
| 151 ret := make([]memcache.Item, len(mcKeys)) | 152 ret := make([]memcache.Item, len(mcKeys)) |
| 152 for i := range ret { | 153 for i := range ret { |
| 153 ret[i] = (s.mc.NewItem(mcKeys[i]). | 154 ret[i] = (s.mc.NewItem(mcKeys[i]). |
| 154 SetFlags(uint32(ItemHasLock)). | 155 SetFlags(uint32(ItemHasLock)). |
| 155 SetExpiration(time.Second * time.Duration(LockTimeSecond
s))) | 156 SetExpiration(time.Second * time.Duration(LockTimeSecond
s))) |
| 156 } | 157 } |
| 157 return ret, mcKeys | 158 return ret, mcKeys |
| 158 } | 159 } |
| OLD | NEW |