| Index: impl/memory/memcache.go
|
| diff --git a/memory/memcache.go b/impl/memory/memcache.go
|
| similarity index 78%
|
| rename from memory/memcache.go
|
| rename to impl/memory/memcache.go
|
| index 82efe4b4df4f4fa8978256104fefde2f8b8caacb..99617c0ccf03fb9aa2758e1ce052ae88bbfa2abf 100644
|
| --- a/memory/memcache.go
|
| +++ b/impl/memory/memcache.go
|
| @@ -10,9 +10,8 @@ import (
|
|
|
| "golang.org/x/net/context"
|
|
|
| - "github.com/luci/gae"
|
| - "github.com/luci/gae/dummy"
|
| -
|
| + "github.com/luci/gae/impl/dummy"
|
| + mc "github.com/luci/gae/service/memcache"
|
| "github.com/luci/luci-go/common/clock"
|
| )
|
|
|
| @@ -26,7 +25,7 @@ type mcItem struct {
|
| CasID uint64
|
| }
|
|
|
| -var _ gae.MCItem = (*mcItem)(nil)
|
| +var _ mc.Item = (*mcItem)(nil)
|
|
|
| func (m *mcItem) Key() string { return m.key }
|
| func (m *mcItem) Value() []byte { return m.value }
|
| @@ -34,23 +33,23 @@ func (m *mcItem) Object() interface{} { return m.object }
|
| func (m *mcItem) Flags() uint32 { return m.flags }
|
| func (m *mcItem) Expiration() time.Duration { return m.expiration }
|
|
|
| -func (m *mcItem) SetKey(key string) gae.MCItem {
|
| +func (m *mcItem) SetKey(key string) mc.Item {
|
| m.key = key
|
| return m
|
| }
|
| -func (m *mcItem) SetValue(val []byte) gae.MCItem {
|
| +func (m *mcItem) SetValue(val []byte) mc.Item {
|
| m.value = val
|
| return m
|
| }
|
| -func (m *mcItem) SetObject(obj interface{}) gae.MCItem {
|
| +func (m *mcItem) SetObject(obj interface{}) mc.Item {
|
| m.object = obj
|
| return m
|
| }
|
| -func (m *mcItem) SetFlags(flg uint32) gae.MCItem {
|
| +func (m *mcItem) SetFlags(flg uint32) mc.Item {
|
| m.flags = flg
|
| return m
|
| }
|
| -func (m *mcItem) SetExpiration(exp time.Duration) gae.MCItem {
|
| +func (m *mcItem) SetExpiration(exp time.Duration) mc.Item {
|
| m.expiration = exp
|
| return m
|
| }
|
| @@ -72,13 +71,13 @@ type memcacheData struct {
|
| // memcacheImpl binds the current connection's memcache data to an
|
| // implementation of {gae.Memcache, gae.Testable}.
|
| type memcacheImpl struct {
|
| - gae.Memcache
|
| + mc.Interface
|
|
|
| data *memcacheData
|
| ctx context.Context
|
| }
|
|
|
| -var _ gae.Memcache = (*memcacheImpl)(nil)
|
| +var _ mc.Interface = (*memcacheImpl)(nil)
|
|
|
| // useMC adds a gae.Memcache implementation to context, accessible
|
| // by gae.GetMC(c)
|
| @@ -86,7 +85,7 @@ func useMC(c context.Context) context.Context {
|
| lck := sync.Mutex{}
|
| mcdMap := map[string]*memcacheData{}
|
|
|
| - return gae.SetMCFactory(c, func(ic context.Context) gae.Memcache {
|
| + return mc.SetFactory(c, func(ic context.Context) mc.Interface {
|
| lck.Lock()
|
| defer lck.Unlock()
|
|
|
| @@ -98,14 +97,14 @@ func useMC(c context.Context) context.Context {
|
| }
|
|
|
| return &memcacheImpl{
|
| - dummy.MC(),
|
| + dummy.Memcache(),
|
| mcd,
|
| ic,
|
| }
|
| })
|
| }
|
|
|
| -func (m *memcacheImpl) mkItemLocked(i gae.MCItem) (ret *mcItem) {
|
| +func (m *memcacheImpl) mkItemLocked(i mc.Item) (ret *mcItem) {
|
| m.data.casID++
|
|
|
| var exp time.Duration
|
| @@ -122,12 +121,12 @@ func (m *memcacheImpl) mkItemLocked(i gae.MCItem) (ret *mcItem) {
|
| return newItem.duplicate()
|
| }
|
|
|
| -func (m *memcacheImpl) NewItem(key string) gae.MCItem {
|
| +func (m *memcacheImpl) NewItem(key string) mc.Item {
|
| return &mcItem{key: key}
|
| }
|
|
|
| // Add implements context.MCSingleReadWriter.Add.
|
| -func (m *memcacheImpl) Add(i gae.MCItem) error {
|
| +func (m *memcacheImpl) Add(i mc.Item) error {
|
| m.data.lock.Lock()
|
| defer m.data.lock.Unlock()
|
|
|
| @@ -135,11 +134,11 @@ func (m *memcacheImpl) Add(i gae.MCItem) error {
|
| m.data.items[i.Key()] = m.mkItemLocked(i)
|
| return nil
|
| }
|
| - return gae.ErrMCNotStored
|
| + return mc.ErrNotStored
|
| }
|
|
|
| // CompareAndSwap implements context.MCSingleReadWriter.CompareAndSwap.
|
| -func (m *memcacheImpl) CompareAndSwap(item gae.MCItem) error {
|
| +func (m *memcacheImpl) CompareAndSwap(item mc.Item) error {
|
| m.data.lock.Lock()
|
| defer m.data.lock.Unlock()
|
|
|
| @@ -152,16 +151,16 @@ func (m *memcacheImpl) CompareAndSwap(item gae.MCItem) error {
|
| if cur.CasID == casid {
|
| m.data.items[item.Key()] = m.mkItemLocked(item)
|
| } else {
|
| - return gae.ErrMCCASConflict
|
| + return mc.ErrCASConflict
|
| }
|
| } else {
|
| - return gae.ErrMCNotStored
|
| + return mc.ErrNotStored
|
| }
|
| return nil
|
| }
|
|
|
| // Set implements context.MCSingleReadWriter.Set.
|
| -func (m *memcacheImpl) Set(i gae.MCItem) error {
|
| +func (m *memcacheImpl) Set(i mc.Item) error {
|
| m.data.lock.Lock()
|
| defer m.data.lock.Unlock()
|
| m.data.items[i.Key()] = m.mkItemLocked(i)
|
| @@ -169,13 +168,13 @@ func (m *memcacheImpl) Set(i gae.MCItem) error {
|
| }
|
|
|
| // Get implements context.MCSingleReadWriter.Get.
|
| -func (m *memcacheImpl) Get(key string) (itm gae.MCItem, err error) {
|
| +func (m *memcacheImpl) Get(key string) (itm mc.Item, err error) {
|
| m.data.lock.Lock()
|
| defer m.data.lock.Unlock()
|
| if val, ok := m.retrieveLocked(key); ok {
|
| itm = val.duplicate().SetExpiration(0)
|
| } else {
|
| - err = gae.ErrMCCacheMiss
|
| + err = mc.ErrCacheMiss
|
| }
|
| return
|
| }
|
| @@ -189,7 +188,7 @@ func (m *memcacheImpl) Delete(key string) error {
|
| delete(m.data.items, key)
|
| return nil
|
| }
|
| - return gae.ErrMCCacheMiss
|
| + return mc.ErrCacheMiss
|
| }
|
|
|
| func (m *memcacheImpl) retrieveLocked(key string) (*mcItem, bool) {
|
|
|