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 prod | 5 package prod |
6 | 6 |
7 import ( | 7 import ( |
8 "time" | 8 "time" |
9 | 9 |
10 "github.com/luci/gae" | |
11 mc "github.com/luci/gae/service/memcache" | 10 mc "github.com/luci/gae/service/memcache" |
| 11 "github.com/luci/luci-go/common/errors" |
12 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
13 "google.golang.org/appengine/memcache" | 13 "google.golang.org/appengine/memcache" |
14 ) | 14 ) |
15 | 15 |
16 // useMC adds a gae.Memcache implementation to context, accessible | 16 // useMC adds a gae.Memcache implementation to context, accessible |
17 // by gae.GetMC(c) | 17 // by gae.GetMC(c) |
18 func useMC(c context.Context) context.Context { | 18 func useMC(c context.Context) context.Context { |
19 return mc.SetFactory(c, func(ci context.Context) mc.Interface { | 19 return mc.SetFactory(c, func(ci context.Context) mc.Interface { |
20 return mcImpl{ci} | 20 return mcImpl{ci} |
21 }) | 21 }) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 func (m mcImpl) Get(key string) (mc.Item, error) { | 104 func (m mcImpl) Get(key string) (mc.Item, error) { |
105 return mcR2FErr(memcache.Get(m.Context, key)) | 105 return mcR2FErr(memcache.Get(m.Context, key)) |
106 } | 106 } |
107 func (m mcImpl) CompareAndSwap(item mc.Item) error { | 107 func (m mcImpl) CompareAndSwap(item mc.Item) error { |
108 return memcache.CompareAndSwap(m.Context, mcF2R(item)) | 108 return memcache.CompareAndSwap(m.Context, mcF2R(item)) |
109 } | 109 } |
110 | 110 |
111 //////// MCMultiReadWriter | 111 //////// MCMultiReadWriter |
112 func (m mcImpl) DeleteMulti(keys []string) error { | 112 func (m mcImpl) DeleteMulti(keys []string) error { |
113 » return gae.FixError(memcache.DeleteMulti(m.Context, keys)) | 113 » return errors.Fix(memcache.DeleteMulti(m.Context, keys)) |
114 } | 114 } |
115 func (m mcImpl) AddMulti(items []mc.Item) error { | 115 func (m mcImpl) AddMulti(items []mc.Item) error { |
116 » return gae.FixError(memcache.AddMulti(m.Context, mcMF2R(items))) | 116 » return errors.Fix(memcache.AddMulti(m.Context, mcMF2R(items))) |
117 } | 117 } |
118 func (m mcImpl) SetMulti(items []mc.Item) error { | 118 func (m mcImpl) SetMulti(items []mc.Item) error { |
119 » return gae.FixError(memcache.SetMulti(m.Context, mcMF2R(items))) | 119 » return errors.Fix(memcache.SetMulti(m.Context, mcMF2R(items))) |
120 } | 120 } |
121 func (m mcImpl) GetMulti(keys []string) (map[string]mc.Item, error) { | 121 func (m mcImpl) GetMulti(keys []string) (map[string]mc.Item, error) { |
122 realItems, err := memcache.GetMulti(m.Context, keys) | 122 realItems, err := memcache.GetMulti(m.Context, keys) |
123 if err != nil { | 123 if err != nil { |
124 » » return nil, gae.FixError(err) | 124 » » return nil, errors.Fix(err) |
125 } | 125 } |
126 items := make(map[string]mc.Item, len(realItems)) | 126 items := make(map[string]mc.Item, len(realItems)) |
127 for k, itm := range realItems { | 127 for k, itm := range realItems { |
128 items[k] = mcItem{itm} | 128 items[k] = mcItem{itm} |
129 } | 129 } |
130 return items, err | 130 return items, err |
131 } | 131 } |
132 func (m mcImpl) CompareAndSwapMulti(items []mc.Item) error { | 132 func (m mcImpl) CompareAndSwapMulti(items []mc.Item) error { |
133 » return gae.FixError(memcache.CompareAndSwapMulti(m.Context, mcMF2R(items
))) | 133 » return errors.Fix(memcache.CompareAndSwapMulti(m.Context, mcMF2R(items))
) |
134 } | 134 } |
135 | 135 |
136 //////// MCIncrementer | 136 //////// MCIncrementer |
137 func (m mcImpl) Increment(key string, delta int64, initialValue uint64) (uint64,
error) { | 137 func (m mcImpl) Increment(key string, delta int64, initialValue uint64) (uint64,
error) { |
138 return memcache.Increment(m.Context, key, delta, initialValue) | 138 return memcache.Increment(m.Context, key, delta, initialValue) |
139 } | 139 } |
140 func (m mcImpl) IncrementExisting(key string, delta int64) (uint64, error) { | 140 func (m mcImpl) IncrementExisting(key string, delta int64) (uint64, error) { |
141 return memcache.IncrementExisting(m.Context, key, delta) | 141 return memcache.IncrementExisting(m.Context, key, delta) |
142 } | 142 } |
143 | 143 |
144 //////// MCFlusher | 144 //////// MCFlusher |
145 func (m mcImpl) Flush() error { | 145 func (m mcImpl) Flush() error { |
146 return memcache.Flush(m.Context) | 146 return memcache.Flush(m.Context) |
147 } | 147 } |
148 | 148 |
149 //////// MCStatter | 149 //////// MCStatter |
150 func (m mcImpl) Stats() (*mc.Statistics, error) { | 150 func (m mcImpl) Stats() (*mc.Statistics, error) { |
151 stats, err := memcache.Stats(m.Context) | 151 stats, err := memcache.Stats(m.Context) |
152 if err != nil { | 152 if err != nil { |
153 return nil, err | 153 return nil, err |
154 } | 154 } |
155 return (*mc.Statistics)(stats), nil | 155 return (*mc.Statistics)(stats), nil |
156 } | 156 } |
OLD | NEW |