Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. diff --git a/memcache.go b/memcache.go.txt
  2. index ece54b4..d8eed4b 100644
  3. --- a/memcache.go
  4. +++ b/memcache.go.txt
  5. @@ -26,7 +26,7 @@
  6. // if err := memcache.Set(c, item1); err != nil {
  7. // return err
  8. // }
  9. -package memcache
  10. +package memcache // import "google.golang.org/appengine/memcache"
  11.  
  12. import (
  13. "bytes"
  14. @@ -35,11 +35,12 @@ import (
  15. "errors"
  16. "time"
  17.  
  18. - "appengine"
  19. - "appengine_internal"
  20. "github.com/golang/protobuf/proto"
  21. + "golang.org/x/net/context"
  22.  
  23. - pb "appengine_internal/memcache"
  24. + "google.golang.org/appengine"
  25. + "google.golang.org/appengine/internal"
  26. + pb "google.golang.org/appengine/internal/memcache"
  27. )
  28.  
  29. var (
  30. @@ -107,7 +108,7 @@ func singleError(err error) error {
  31.  
  32. // Get gets the item for the given key. ErrCacheMiss is returned for a memcache
  33. // cache miss. The key must be at most 250 bytes in length.
  34. -func Get(c appengine.Context, key string) (*Item, error) {
  35. +func Get(c context.Context, key string) (*Item, error) {
  36. m, err := GetMulti(c, []string{key})
  37. if err != nil {
  38. return nil, err
  39. @@ -121,7 +122,7 @@ func Get(c appengine.Context, key string) (*Item, error) {
  40. // GetMulti is a batch version of Get. The returned map from keys to items may
  41. // have fewer elements than the input slice, due to memcache cache misses.
  42. // Each key must be at most 250 bytes in length.
  43. -func GetMulti(c appengine.Context, key []string) (map[string]*Item, error) {
  44. +func GetMulti(c context.Context, key []string) (map[string]*Item, error) {
  45. if len(key) == 0 {
  46. return nil, nil
  47. }
  48. @@ -134,7 +135,7 @@ func GetMulti(c appengine.Context, key []string) (map[string]*Item, error) {
  49. ForCas: proto.Bool(true),
  50. }
  51. res := &pb.MemcacheGetResponse{}
  52. - if err := c.Call("memcache", "Get", req, res, nil); err != nil {
  53. + if err := internal.Call(c, "memcache", "Get", req, res); err != nil {
  54. return nil, err
  55. }
  56. m := make(map[string]*Item, len(res.Item))
  57. @@ -148,14 +149,14 @@ func GetMulti(c appengine.Context, key []string) (map[string]*Item, error) {
  58. // Delete deletes the item for the given key.
  59. // ErrCacheMiss is returned if the specified item can not be found.
  60. // The key must be at most 250 bytes in length.
  61. -func Delete(c appengine.Context, key string) error {
  62. +func Delete(c context.Context, key string) error {
  63. return singleError(DeleteMulti(c, []string{key}))
  64. }
  65.  
  66. // DeleteMulti is a batch version of Delete.
  67. // If any keys cannot be found, an appengine.MultiError is returned.
  68. // Each key must be at most 250 bytes in length.
  69. -func DeleteMulti(c appengine.Context, key []string) error {
  70. +func DeleteMulti(c context.Context, key []string) error {
  71. if len(key) == 0 {
  72. return nil
  73. }
  74. @@ -166,7 +167,7 @@ func DeleteMulti(c appengine.Context, key []string) error {
  75. req.Item[i] = &pb.MemcacheDeleteRequest_Item{Key: []byte(k)}
  76. }
  77. res := &pb.MemcacheDeleteResponse{}
  78. - if err := c.Call("memcache", "Delete", req, res, nil); err != nil {
  79. + if err := internal.Call(c, "memcache", "Delete", req, res); err != nil {
  80. return err
  81. }
  82. if len(res.DeleteStatus) != len(key) {
  83. @@ -198,7 +199,7 @@ func DeleteMulti(c appengine.Context, key []string) error {
  84. // memcache, the provided initial value is used to atomically
  85. // populate it before the delta is applied.
  86. // The key must be at most 250 bytes in length.
  87. -func Increment(c appengine.Context, key string, delta int64, initialValue uint64) (newValue uint64, err error) {
  88. +func Increment(c context.Context, key string, delta int64, initialValue uint64) (newValue uint64, err error) {
  89. return incr(c, key, delta, &initialValue)
  90. }
  91.  
  92. @@ -207,11 +208,11 @@ func Increment(c appengine.Context, key string, delta int64, initialValue uint64
  93. // IncrementExisting can save work if calculating the initial value is
  94. // expensive.
  95. // An error is returned if the specified item can not be found.
  96. -func IncrementExisting(c appengine.Context, key string, delta int64) (newValue uint64, err error) {
  97. +func IncrementExisting(c context.Context, key string, delta int64) (newValue uint64, err error) {
  98. return incr(c, key, delta, nil)
  99. }
  100.  
  101. -func incr(c appengine.Context, key string, delta int64, initialValue *uint64) (newValue uint64, err error) {
  102. +func incr(c context.Context, key string, delta int64, initialValue *uint64) (newValue uint64, err error) {
  103. req := &pb.MemcacheIncrementRequest{
  104. Key: []byte(key),
  105. InitialValue: initialValue,
  106. @@ -223,7 +224,7 @@ func incr(c appengine.Context, key string, delta int64, initialValue *uint64) (n
  107. req.Direction = pb.MemcacheIncrementRequest_DECREMENT.Enum()
  108. }
  109. res := &pb.MemcacheIncrementResponse{}
  110. - err = c.Call("memcache", "Increment", req, res, nil)
  111. + err = internal.Call(c, "memcache", "Increment", req, res)
  112. if err != nil {
  113. return
  114. }
  115. @@ -235,7 +236,7 @@ func incr(c appengine.Context, key string, delta int64, initialValue *uint64) (n
  116.  
  117. // set sets the given items using the given conflict resolution policy.
  118. // appengine.MultiError may be returned.
  119. -func set(c appengine.Context, item []*Item, value [][]byte, policy pb.MemcacheSetRequest_SetPolicy) error {
  120. +func set(c context.Context, item []*Item, value [][]byte, policy pb.MemcacheSetRequest_SetPolicy) error {
  121. if len(item) == 0 {
  122. return nil
  123. }
  124. @@ -282,7 +283,7 @@ func set(c appengine.Context, item []*Item, value [][]byte, policy pb.MemcacheSe
  125. req.Item[i] = p
  126. }
  127. res := &pb.MemcacheSetResponse{}
  128. - if err := c.Call("memcache", "Set", req, res, nil); err != nil {
  129. + if err := internal.Call(c, "memcache", "Set", req, res); err != nil {
  130. return err
  131. }
  132. if len(res.SetStatus) != len(item) {
  133. @@ -313,25 +314,25 @@ func set(c appengine.Context, item []*Item, value [][]byte, policy pb.MemcacheSe
  134. }
  135.  
  136. // Set writes the given item, unconditionally.
  137. -func Set(c appengine.Context, item *Item) error {
  138. +func Set(c context.Context, item *Item) error {
  139. return singleError(set(c, []*Item{item}, nil, pb.MemcacheSetRequest_SET))
  140. }
  141.  
  142. // SetMulti is a batch version of Set.
  143. // appengine.MultiError may be returned.
  144. -func SetMulti(c appengine.Context, item []*Item) error {
  145. +func SetMulti(c context.Context, item []*Item) error {
  146. return set(c, item, nil, pb.MemcacheSetRequest_SET)
  147. }
  148.  
  149. // Add writes the given item, if no value already exists for its key.
  150. // ErrNotStored is returned if that condition is not met.
  151. -func Add(c appengine.Context, item *Item) error {
  152. +func Add(c context.Context, item *Item) error {
  153. return singleError(set(c, []*Item{item}, nil, pb.MemcacheSetRequest_ADD))
  154. }
  155.  
  156. // AddMulti is a batch version of Add.
  157. // appengine.MultiError may be returned.
  158. -func AddMulti(c appengine.Context, item []*Item) error {
  159. +func AddMulti(c context.Context, item []*Item) error {
  160. return set(c, item, nil, pb.MemcacheSetRequest_ADD)
  161. }
  162.  
  163. @@ -341,13 +342,13 @@ func AddMulti(c appengine.Context, item []*Item) error {
  164. // all other item fields may differ.
  165. // ErrCASConflict is returned if the value was modified in between the calls.
  166. // ErrNotStored is returned if the value was evicted in between the calls.
  167. -func CompareAndSwap(c appengine.Context, item *Item) error {
  168. +func CompareAndSwap(c context.Context, item *Item) error {
  169. return singleError(set(c, []*Item{item}, nil, pb.MemcacheSetRequest_CAS))
  170. }
  171.  
  172. // CompareAndSwapMulti is a batch version of CompareAndSwap.
  173. // appengine.MultiError may be returned.
  174. -func CompareAndSwapMulti(c appengine.Context, item []*Item) error {
  175. +func CompareAndSwapMulti(c context.Context, item []*Item) error {
  176. return set(c, item, nil, pb.MemcacheSetRequest_CAS)
  177. }
  178.  
  179. @@ -365,7 +366,7 @@ type Codec struct {
  180. // Get gets the item for the given key and decodes the obtained value into v.
  181. // ErrCacheMiss is returned for a memcache cache miss.
  182. // The key must be at most 250 bytes in length.
  183. -func (cd Codec) Get(c appengine.Context, key string, v interface{}) (*Item, error) {
  184. +func (cd Codec) Get(c context.Context, key string, v interface{}) (*Item, error) {
  185. i, err := Get(c, key)
  186. if err != nil {
  187. return nil, err
  188. @@ -376,7 +377,7 @@ func (cd Codec) Get(c appengine.Context, key string, v interface{}) (*Item, erro
  189. return i, nil
  190. }
  191.  
  192. -func (cd Codec) set(c appengine.Context, items []*Item, policy pb.MemcacheSetRequest_SetPolicy) error {
  193. +func (cd Codec) set(c context.Context, items []*Item, policy pb.MemcacheSetRequest_SetPolicy) error {
  194. var vs [][]byte
  195. var me appengine.MultiError
  196. for i, item := range items {
  197. @@ -400,25 +401,25 @@ func (cd Codec) set(c appengine.Context, items []*Item, policy pb.MemcacheSetReq
  198. }
  199.  
  200. // Set writes the given item, unconditionally.
  201. -func (cd Codec) Set(c appengine.Context, item *Item) error {
  202. +func (cd Codec) Set(c context.Context, item *Item) error {
  203. return singleError(cd.set(c, []*Item{item}, pb.MemcacheSetRequest_SET))
  204. }
  205.  
  206. // SetMulti is a batch version of Set.
  207. // appengine.MultiError may be returned.
  208. -func (cd Codec) SetMulti(c appengine.Context, items []*Item) error {
  209. +func (cd Codec) SetMulti(c context.Context, items []*Item) error {
  210. return cd.set(c, items, pb.MemcacheSetRequest_SET)
  211. }
  212.  
  213. // Add writes the given item, if no value already exists for its key.
  214. // ErrNotStored is returned if that condition is not met.
  215. -func (cd Codec) Add(c appengine.Context, item *Item) error {
  216. +func (cd Codec) Add(c context.Context, item *Item) error {
  217. return singleError(cd.set(c, []*Item{item}, pb.MemcacheSetRequest_ADD))
  218. }
  219.  
  220. // AddMulti is a batch version of Add.
  221. // appengine.MultiError may be returned.
  222. -func (cd Codec) AddMulti(c appengine.Context, items []*Item) error {
  223. +func (cd Codec) AddMulti(c context.Context, items []*Item) error {
  224. return cd.set(c, items, pb.MemcacheSetRequest_ADD)
  225. }
  226.  
  227. @@ -428,13 +429,13 @@ func (cd Codec) AddMulti(c appengine.Context, items []*Item) error {
  228. // all other item fields may differ.
  229. // ErrCASConflict is returned if the value was modified in between the calls.
  230. // ErrNotStored is returned if the value was evicted in between the calls.
  231. -func (cd Codec) CompareAndSwap(c appengine.Context, item *Item) error {
  232. +func (cd Codec) CompareAndSwap(c context.Context, item *Item) error {
  233. return singleError(cd.set(c, []*Item{item}, pb.MemcacheSetRequest_CAS))
  234. }
  235.  
  236. // CompareAndSwapMulti is a batch version of CompareAndSwap.
  237. // appengine.MultiError may be returned.
  238. -func (cd Codec) CompareAndSwapMulti(c appengine.Context, items []*Item) error {
  239. +func (cd Codec) CompareAndSwapMulti(c context.Context, items []*Item) error {
  240. return cd.set(c, items, pb.MemcacheSetRequest_CAS)
  241. }
  242.  
  243. @@ -471,10 +472,10 @@ type Statistics struct {
  244. }
  245.  
  246. // Stats retrieves the current memcache statistics.
  247. -func Stats(c appengine.Context) (*Statistics, error) {
  248. +func Stats(c context.Context) (*Statistics, error) {
  249. req := &pb.MemcacheStatsRequest{}
  250. res := &pb.MemcacheStatsResponse{}
  251. - if err := c.Call("memcache", "Stats", req, res, nil); err != nil {
  252. + if err := internal.Call(c, "memcache", "Stats", req, res); err != nil {
  253. return nil, err
  254. }
  255. if res.Stats == nil {
  256. @@ -491,13 +492,13 @@ func Stats(c appengine.Context) (*Statistics, error) {
  257. }
  258.  
  259. // Flush flushes all items from memcache.
  260. -func Flush(c appengine.Context) error {
  261. +func Flush(c context.Context) error {
  262. req := &pb.MemcacheFlushRequest{}
  263. res := &pb.MemcacheFlushResponse{}
  264. - return c.Call("memcache", "FlushAll", req, res, nil)
  265. + return internal.Call(c, "memcache", "FlushAll", req, res)
  266. }
  267.  
  268. -func namespaceMod(m appengine_internal.ProtoMessage, namespace string) {
  269. +func namespaceMod(m proto.Message, namespace string) {
  270. switch m := m.(type) {
  271. case *pb.MemcacheDeleteRequest:
  272. if m.NameSpace == nil {
  273. @@ -520,6 +521,6 @@ func namespaceMod(m appengine_internal.ProtoMessage, namespace string) {
  274. }
  275.  
  276. func init() {
  277. - appengine_internal.RegisterErrorCodeMap("memcache", pb.MemcacheServiceError_ErrorCode_name)
  278. - appengine_internal.NamespaceMods["memcache"] = namespaceMod
  279. + internal.RegisterErrorCodeMap("memcache", pb.MemcacheServiceError_ErrorCode_name)
  280. + internal.NamespaceMods["memcache"] = namespaceMod
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement