Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: impl/prod/memcache.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/prod/info.go ('k') | impl/prod/raw_datastore.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/prod/memcache.go
diff --git a/prod/memcache.go b/impl/prod/memcache.go
similarity index 68%
rename from prod/memcache.go
rename to impl/prod/memcache.go
index 8a403d7a9e253dc102500e072b8689b1a26391ec..fc267c3e02c8590d26608892d66df3badbcc3ca1 100644
--- a/prod/memcache.go
+++ b/impl/prod/memcache.go
@@ -8,6 +8,7 @@ import (
"time"
"github.com/luci/gae"
+ mc "github.com/luci/gae/service/memcache"
"golang.org/x/net/context"
"google.golang.org/appengine/memcache"
)
@@ -15,7 +16,7 @@ import (
// useMC adds a gae.Memcache implementation to context, accessible
// by gae.GetMC(c)
func useMC(c context.Context) context.Context {
- return gae.SetMCFactory(c, func(ci context.Context) gae.Memcache {
+ return mc.SetFactory(c, func(ci context.Context) mc.Interface {
return mcImpl{ci}
})
}
@@ -26,7 +27,7 @@ type mcItem struct {
i *memcache.Item
}
-var _ gae.MCItem = mcItem{}
+var _ mc.Item = mcItem{}
func (i mcItem) Key() string { return i.i.Key }
func (i mcItem) Value() []byte { return i.i.Value }
@@ -34,51 +35,51 @@ func (i mcItem) Object() interface{} { return i.i.Object }
func (i mcItem) Flags() uint32 { return i.i.Flags }
func (i mcItem) Expiration() time.Duration { return i.i.Expiration }
-func (i mcItem) SetKey(k string) gae.MCItem {
+func (i mcItem) SetKey(k string) mc.Item {
i.i.Key = k
return i
}
-func (i mcItem) SetValue(v []byte) gae.MCItem {
+func (i mcItem) SetValue(v []byte) mc.Item {
i.i.Value = v
return i
}
-func (i mcItem) SetObject(o interface{}) gae.MCItem {
+func (i mcItem) SetObject(o interface{}) mc.Item {
i.i.Object = o
return i
}
-func (i mcItem) SetFlags(f uint32) gae.MCItem {
+func (i mcItem) SetFlags(f uint32) mc.Item {
i.i.Flags = f
return i
}
-func (i mcItem) SetExpiration(d time.Duration) gae.MCItem {
+func (i mcItem) SetExpiration(d time.Duration) mc.Item {
i.i.Expiration = d
return i
}
-// mcR2FErr (MC real-to-fake w/ error) converts a *memcache.Item to a gae.MCItem,
+// mcR2FErr (MC real-to-fake w/ error) converts a *memcache.Item to a mc.Item,
// and passes along an error.
-func mcR2FErr(i *memcache.Item, err error) (gae.MCItem, error) {
+func mcR2FErr(i *memcache.Item, err error) (mc.Item, error) {
if err != nil {
return nil, err
}
return mcItem{i}, nil
}
-// mcF2R (MC fake-to-real) converts a gae.MCItem. i must originate from inside
+// mcF2R (MC fake-to-real) converts a mc.Item. i must originate from inside
// this package for this function to work (see the panic message for why).
-func mcF2R(i gae.MCItem) *memcache.Item {
+func mcF2R(i mc.Item) *memcache.Item {
if mci, ok := i.(mcItem); ok {
return mci.i
}
panic(
- "you may not use other gae.MCItem implementations with this " +
+ "you may not use other mc.Item implementations with this " +
"implementation of gae.Memcache, since it will cause all CompareAndSwap " +
"operations to fail. Please use the NewItem api instead.")
}
-// mcMF2R (MC multi-fake-to-real) converts a slice of gae.MCItem to a slice of
+// mcMF2R (MC multi-fake-to-real) converts a slice of mc.Item to a slice of
// *memcache.Item.
-func mcMF2R(items []gae.MCItem) []*memcache.Item {
+func mcMF2R(items []mc.Item) []*memcache.Item {
realItems := make([]*memcache.Item, len(items))
for i, itm := range items {
realItems[i] = mcF2R(itm)
@@ -86,24 +87,24 @@ func mcMF2R(items []gae.MCItem) []*memcache.Item {
return realItems
}
-func (m mcImpl) NewItem(key string) gae.MCItem {
+func (m mcImpl) NewItem(key string) mc.Item {
return mcItem{&memcache.Item{Key: key}}
}
//////// MCSingleReadWriter
-func (m mcImpl) Add(item gae.MCItem) error {
+func (m mcImpl) Add(item mc.Item) error {
return memcache.Add(m.Context, mcF2R(item))
}
-func (m mcImpl) Set(item gae.MCItem) error {
+func (m mcImpl) Set(item mc.Item) error {
return memcache.Set(m.Context, mcF2R(item))
}
func (m mcImpl) Delete(key string) error {
return memcache.Delete(m.Context, key)
}
-func (m mcImpl) Get(key string) (gae.MCItem, error) {
+func (m mcImpl) Get(key string) (mc.Item, error) {
return mcR2FErr(memcache.Get(m.Context, key))
}
-func (m mcImpl) CompareAndSwap(item gae.MCItem) error {
+func (m mcImpl) CompareAndSwap(item mc.Item) error {
return memcache.CompareAndSwap(m.Context, mcF2R(item))
}
@@ -111,24 +112,24 @@ func (m mcImpl) CompareAndSwap(item gae.MCItem) error {
func (m mcImpl) DeleteMulti(keys []string) error {
return gae.FixError(memcache.DeleteMulti(m.Context, keys))
}
-func (m mcImpl) AddMulti(items []gae.MCItem) error {
+func (m mcImpl) AddMulti(items []mc.Item) error {
return gae.FixError(memcache.AddMulti(m.Context, mcMF2R(items)))
}
-func (m mcImpl) SetMulti(items []gae.MCItem) error {
+func (m mcImpl) SetMulti(items []mc.Item) error {
return gae.FixError(memcache.SetMulti(m.Context, mcMF2R(items)))
}
-func (m mcImpl) GetMulti(keys []string) (map[string]gae.MCItem, error) {
+func (m mcImpl) GetMulti(keys []string) (map[string]mc.Item, error) {
realItems, err := memcache.GetMulti(m.Context, keys)
if err != nil {
return nil, gae.FixError(err)
}
- items := make(map[string]gae.MCItem, len(realItems))
+ items := make(map[string]mc.Item, len(realItems))
for k, itm := range realItems {
items[k] = mcItem{itm}
}
return items, err
}
-func (m mcImpl) CompareAndSwapMulti(items []gae.MCItem) error {
+func (m mcImpl) CompareAndSwapMulti(items []mc.Item) error {
return gae.FixError(memcache.CompareAndSwapMulti(m.Context, mcMF2R(items)))
}
@@ -146,10 +147,10 @@ func (m mcImpl) Flush() error {
}
//////// MCStatter
-func (m mcImpl) Stats() (*gae.MCStatistics, error) {
+func (m mcImpl) Stats() (*mc.Statistics, error) {
stats, err := memcache.Stats(m.Context)
if err != nil {
return nil, err
}
- return (*gae.MCStatistics)(stats), nil
+ return (*mc.Statistics)(stats), nil
}
« no previous file with comments | « impl/prod/info.go ('k') | impl/prod/raw_datastore.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698