OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package gae |
| 6 |
| 7 import ( |
| 8 "golang.org/x/net/context" |
| 9 |
| 10 "appengine" |
| 11 "appengine/memcache" |
| 12 |
| 13 "infra/gae/libs/wrapper" |
| 14 ) |
| 15 |
| 16 // useMC adds a wrapper.Memcache implementation to context, accessible |
| 17 // by wrapper.GetMC(c) |
| 18 func useMC(c context.Context) context.Context { |
| 19 return wrapper.SetMCFactory(c, func(ci context.Context) wrapper.Memcache
{ |
| 20 return mcImpl{ctx(c).Context} |
| 21 }) |
| 22 } |
| 23 |
| 24 type mcImpl struct { |
| 25 appengine.Context |
| 26 } |
| 27 |
| 28 //////// MCSingleReadWriter |
| 29 func (m mcImpl) Add(item *memcache.Item) error { |
| 30 return memcache.Add(m.Context, item) |
| 31 } |
| 32 func (m mcImpl) Set(item *memcache.Item) error { |
| 33 return memcache.Set(m.Context, item) |
| 34 } |
| 35 func (m mcImpl) Delete(key string) error { |
| 36 return memcache.Delete(m.Context, key) |
| 37 } |
| 38 func (m mcImpl) Get(key string) (*memcache.Item, error) { |
| 39 return memcache.Get(m.Context, key) |
| 40 } |
| 41 func (m mcImpl) CompareAndSwap(item *memcache.Item) error { |
| 42 return memcache.CompareAndSwap(m.Context, item) |
| 43 } |
| 44 |
| 45 //////// MCMultiReadWriter |
| 46 func (m mcImpl) DeleteMulti(keys []string) error { |
| 47 return memcache.DeleteMulti(m.Context, keys) |
| 48 } |
| 49 func (m mcImpl) AddMulti(items []*memcache.Item) error { |
| 50 return memcache.AddMulti(m.Context, items) |
| 51 } |
| 52 func (m mcImpl) SetMulti(items []*memcache.Item) error { |
| 53 return memcache.SetMulti(m.Context, items) |
| 54 } |
| 55 func (m mcImpl) GetMulti(keys []string) (map[string]*memcache.Item, error) { |
| 56 return memcache.GetMulti(m.Context, keys) |
| 57 } |
| 58 func (m mcImpl) CompareAndSwapMulti(items []*memcache.Item) error { |
| 59 return memcache.CompareAndSwapMulti(m.Context, items) |
| 60 } |
| 61 |
| 62 //////// MCIncrementer |
| 63 func (m mcImpl) Increment(key string, delta int64, initialValue uint64) (uint64,
error) { |
| 64 return memcache.Increment(m.Context, key, delta, initialValue) |
| 65 } |
| 66 func (m mcImpl) IncrementExisting(key string, delta int64) (uint64, error) { |
| 67 return memcache.IncrementExisting(m.Context, key, delta) |
| 68 } |
| 69 |
| 70 //////// MCFlusher |
| 71 func (m mcImpl) Flush() error { |
| 72 return memcache.Flush(m.Context) |
| 73 } |
| 74 |
| 75 //////// MCStatter |
| 76 func (m mcImpl) Stats() (*memcache.Statistics, error) { |
| 77 return memcache.Stats(m.Context) |
| 78 } |
| 79 |
| 80 //////// MCCodecInflater |
| 81 type mcCodecCombiner struct { |
| 82 appengine.Context |
| 83 codec memcache.Codec |
| 84 } |
| 85 |
| 86 //////// MCCodecInflater.logger |
| 87 func (cc mcCodecCombiner) Set(item *memcache.Item) error { |
| 88 return cc.codec.Set(cc.Context, item) |
| 89 } |
| 90 func (cc mcCodecCombiner) Add(item *memcache.Item) error { |
| 91 return cc.codec.Add(cc.Context, item) |
| 92 } |
| 93 func (cc mcCodecCombiner) Get(key string, v interface{}) (*memcache.Item, error)
{ |
| 94 return cc.codec.Get(cc.Context, key, v) |
| 95 } |
| 96 func (cc mcCodecCombiner) SetMulti(items []*memcache.Item) error { |
| 97 return cc.codec.SetMulti(cc.Context, items) |
| 98 } |
| 99 func (cc mcCodecCombiner) AddMulti(items []*memcache.Item) error { |
| 100 return cc.codec.AddMulti(cc.Context, items) |
| 101 } |
| 102 func (cc mcCodecCombiner) CompareAndSwap(item *memcache.Item) error { |
| 103 return cc.codec.CompareAndSwap(cc.Context, item) |
| 104 } |
| 105 func (cc mcCodecCombiner) CompareAndSwapMulti(items []*memcache.Item) error { |
| 106 return cc.codec.CompareAndSwapMulti(cc.Context, items) |
| 107 } |
| 108 |
| 109 func (m mcImpl) InflateCodec(codec memcache.Codec) wrapper.MCCodec { |
| 110 return mcCodecCombiner{m.Context, codec} |
| 111 } |
OLD | NEW |