| 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 "encoding/binary" | 8 "encoding/binary" |
| 9 "sync" | 9 "sync" |
| 10 "time" | 10 "time" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 func (m *mcItem) SetFlags(flg uint32) mc.Item { | 43 func (m *mcItem) SetFlags(flg uint32) mc.Item { |
| 44 m.flags = flg | 44 m.flags = flg |
| 45 return m | 45 return m |
| 46 } | 46 } |
| 47 func (m *mcItem) SetExpiration(exp time.Duration) mc.Item { | 47 func (m *mcItem) SetExpiration(exp time.Duration) mc.Item { |
| 48 m.expiration = exp | 48 m.expiration = exp |
| 49 return m | 49 return m |
| 50 } | 50 } |
| 51 | 51 |
| 52 func (m *mcItem) SetAll(other mc.Item) { | 52 func (m *mcItem) SetAll(other mc.Item) { |
| 53 » *m = *other.(*mcItem) | 53 » if other == nil { |
| 54 » » *m = mcItem{key: m.key} |
| 55 » } else { |
| 56 » » k := m.key |
| 57 » » *m = *other.(*mcItem) |
| 58 » » m.key = k |
| 59 » } |
| 54 } | 60 } |
| 55 | 61 |
| 56 type mcDataItem struct { | 62 type mcDataItem struct { |
| 57 value []byte | 63 value []byte |
| 58 flags uint32 | 64 flags uint32 |
| 59 expiration time.Time | 65 expiration time.Time |
| 60 casID uint64 | 66 casID uint64 |
| 61 } | 67 } |
| 62 | 68 |
| 63 func (m *mcDataItem) toUserItem(key string) *mcItem { | 69 func (m *mcDataItem) toUserItem(key string) *mcItem { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 199 |
| 194 func (m *memcacheImpl) AddMulti(items []mc.Item, cb mc.RawCB) error { | 200 func (m *memcacheImpl) AddMulti(items []mc.Item, cb mc.RawCB) error { |
| 195 now := clock.Now(m.ctx) | 201 now := clock.Now(m.ctx) |
| 196 doCBs(items, cb, func(itm mc.Item) error { | 202 doCBs(items, cb, func(itm mc.Item) error { |
| 197 m.data.lock.Lock() | 203 m.data.lock.Lock() |
| 198 defer m.data.lock.Unlock() | 204 defer m.data.lock.Unlock() |
| 199 if !m.data.hasItemLocked(now, itm.Key()) { | 205 if !m.data.hasItemLocked(now, itm.Key()) { |
| 200 m.data.setItemLocked(now, itm) | 206 m.data.setItemLocked(now, itm) |
| 201 return nil | 207 return nil |
| 202 } else { | 208 } else { |
| 203 » » » return (mc.ErrNotStored) | 209 » » » return mc.ErrNotStored |
| 204 } | 210 } |
| 205 }) | 211 }) |
| 206 return nil | 212 return nil |
| 207 } | 213 } |
| 208 | 214 |
| 209 func (m *memcacheImpl) CompareAndSwapMulti(items []mc.Item, cb mc.RawCB) error { | 215 func (m *memcacheImpl) CompareAndSwapMulti(items []mc.Item, cb mc.RawCB) error { |
| 210 now := clock.Now(m.ctx) | 216 now := clock.Now(m.ctx) |
| 211 doCBs(items, cb, func(itm mc.Item) error { | 217 doCBs(items, cb, func(itm mc.Item) error { |
| 212 m.data.lock.Lock() | 218 m.data.lock.Lock() |
| 213 defer m.data.lock.Unlock() | 219 defer m.data.lock.Unlock() |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return cur, nil | 341 return cur, nil |
| 336 } | 342 } |
| 337 | 343 |
| 338 func (m *memcacheImpl) Stats() (*mc.Statistics, error) { | 344 func (m *memcacheImpl) Stats() (*mc.Statistics, error) { |
| 339 m.data.lock.RLock() | 345 m.data.lock.RLock() |
| 340 defer m.data.lock.RUnlock() | 346 defer m.data.lock.RUnlock() |
| 341 | 347 |
| 342 ret := m.data.stats | 348 ret := m.data.stats |
| 343 return &ret, nil | 349 return &ret, nil |
| 344 } | 350 } |
| OLD | NEW |