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 count | |
6 | |
7 import ( | |
8 "golang.org/x/net/context" | |
9 | |
10 mc "github.com/luci/gae/service/memcache" | |
11 ) | |
12 | |
13 // MCCounter is the counter object for the Memcache service. | |
14 type MCCounter struct { | |
15 NewItem Entry | |
16 Add Entry | |
17 Set Entry | |
18 Get Entry | |
19 Delete Entry | |
20 CompareAndSwap Entry | |
21 AddMulti Entry | |
22 SetMulti Entry | |
23 GetMulti Entry | |
24 DeleteMulti Entry | |
25 CompareAndSwapMulti Entry | |
26 Increment Entry | |
27 IncrementExisting Entry | |
28 Flush Entry | |
29 Stats Entry | |
30 } | |
31 | |
32 type mcCounter struct { | |
33 c *MCCounter | |
34 | |
35 mc mc.Interface | |
36 } | |
37 | |
38 var _ mc.Interface = (*mcCounter)(nil) | |
39 | |
40 func (m *mcCounter) NewItem(key string) mc.Item { | |
41 m.c.NewItem.up() | |
42 return m.mc.NewItem(key) | |
43 } | |
44 | |
45 func (m *mcCounter) Get(key string) (mc.Item, error) { | |
46 ret, err := m.mc.Get(key) | |
47 return ret, m.c.Get.up(err) | |
48 } | |
49 | |
50 func (m *mcCounter) GetMulti(keys []string) (map[string]mc.Item, error) { | |
51 ret, err := m.mc.GetMulti(keys) | |
52 return ret, m.c.GetMulti.up(err) | |
53 } | |
54 | |
55 func (m *mcCounter) Add(item mc.Item) error { return m.c.Add.up(m.mc.Add(item))
} | |
56 func (m *mcCounter) Set(item mc.Item) error { return m.c.Set.up(m.mc.Set(item))
} | |
57 func (m *mcCounter) Delete(key string) error { return m.c.Delete.up(m.mc.Delete(
key)) } | |
58 func (m *mcCounter) CompareAndSwap(item mc.Item) error { | |
59 return m.c.CompareAndSwap.up(m.mc.CompareAndSwap(item)) | |
60 } | |
61 func (m *mcCounter) AddMulti(items []mc.Item) error { return m.c.AddMulti.up(m.m
c.AddMulti(items)) } | |
62 func (m *mcCounter) SetMulti(items []mc.Item) error { return m.c.SetMulti.up(m.m
c.SetMulti(items)) } | |
63 func (m *mcCounter) DeleteMulti(keys []string) error { | |
64 return m.c.DeleteMulti.up(m.mc.DeleteMulti(keys)) | |
65 } | |
66 func (m *mcCounter) Flush() error { return m.c.Flush.up(m.mc.Flush()) } | |
67 | |
68 func (m *mcCounter) CompareAndSwapMulti(items []mc.Item) error { | |
69 return m.c.CompareAndSwapMulti.up(m.mc.CompareAndSwapMulti(items)) | |
70 } | |
71 | |
72 func (m *mcCounter) Increment(key string, delta int64, initialValue uint64) (new
Value uint64, err error) { | |
73 ret, err := m.mc.Increment(key, delta, initialValue) | |
74 return ret, m.c.Increment.up(err) | |
75 } | |
76 | |
77 func (m *mcCounter) IncrementExisting(key string, delta int64) (newValue uint64,
err error) { | |
78 ret, err := m.mc.IncrementExisting(key, delta) | |
79 return ret, m.c.IncrementExisting.up(err) | |
80 } | |
81 | |
82 func (m *mcCounter) Stats() (*mc.Statistics, error) { | |
83 ret, err := m.mc.Stats() | |
84 return ret, m.c.Stats.up(err) | |
85 } | |
86 | |
87 // FilterMC installs a counter Memcache filter in the context. | |
88 func FilterMC(c context.Context) (context.Context, *MCCounter) { | |
89 state := &MCCounter{} | |
90 return mc.AddFilters(c, func(ic context.Context, mc mc.Interface) mc.Int
erface { | |
91 return &mcCounter{state, mc} | |
92 }), state | |
93 } | |
OLD | NEW |