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 memcache | 5 package memcache |
6 | 6 |
7 // Interface is the full interface to the memcache service. | 7 // Interface is the full interface to the memcache service. |
| 8 // |
| 9 // The *Multi methods may return a "github.com/luci/luci-go/common/errors".Multi
Error |
| 10 // if the rpc to the server was successful, but, e.g. some of the items were |
| 11 // missing. They may also return a regular error, if, for example, the rpc |
| 12 // failed outright. |
8 type Interface interface { | 13 type Interface interface { |
| 14 // NewItem creates a new, mutable, memcache item. |
9 NewItem(key string) Item | 15 NewItem(key string) Item |
10 | 16 |
| 17 // Add puts a single item into memcache, but only if it didn't exist in |
| 18 // memcache before. |
11 Add(item Item) error | 19 Add(item Item) error |
| 20 |
| 21 // Set the item in memcache, whether or not it exists. |
12 Set(item Item) error | 22 Set(item Item) error |
13 » Get(key string) (Item, error) | 23 |
| 24 » // Get retrieves an item from memcache. Only the key field is read. The
item |
| 25 » // will be mutated to contain the data in the memcache item. |
| 26 » Get(item Item) error |
| 27 |
| 28 » // Delete removes an item from memcache. |
14 Delete(key string) error | 29 Delete(key string) error |
| 30 |
| 31 // CompareAndSwap accepts an item which is the result of Get() or GetMul
ti(). |
| 32 // The Get functions add a secret field to item ('CasID'), which is used
as |
| 33 // the "compare" value for the "CompareAndSwap". The actual "Value" fiel
d of |
| 34 // the object set by the Get functions is the "swap" value. |
| 35 // |
| 36 // Example: |
| 37 // mc := memcache.Get(context) |
| 38 // itm := mc.NewItem("aKey") |
| 39 // mc.Get(itm) // check error |
| 40 // itm.SetValue(append(itm.Value(), []byte("more bytes"))) |
| 41 // mc.CompareAndSwap(itm) // check error |
15 CompareAndSwap(item Item) error | 42 CompareAndSwap(item Item) error |
16 | 43 |
17 AddMulti(items []Item) error | 44 AddMulti(items []Item) error |
18 SetMulti(items []Item) error | 45 SetMulti(items []Item) error |
19 » GetMulti(keys []string) (map[string]Item, error) | 46 » GetMulti(items []Item) error |
20 DeleteMulti(keys []string) error | 47 DeleteMulti(keys []string) error |
21 CompareAndSwapMulti(items []Item) error | 48 CompareAndSwapMulti(items []Item) error |
22 | 49 |
| 50 // Increment adds delta to the uint64 contained at key. If the memcache
key |
| 51 // is missing, it's populated with initialValue before applying delta (i
.e. |
| 52 // the final value would be initialValue+delta). |
| 53 // |
| 54 // Underflow caps at 0, overflow wraps back to 0. |
| 55 // |
| 56 // If key contains a value which is not exactly 8 bytes, it's assumed to |
| 57 // contain non-number data and this method will return an error. |
23 Increment(key string, delta int64, initialValue uint64) (newValue uint64
, err error) | 58 Increment(key string, delta int64, initialValue uint64) (newValue uint64
, err error) |
| 59 |
| 60 // IncrementExisting is like Increment, except that the valu must exist |
| 61 // already. |
24 IncrementExisting(key string, delta int64) (newValue uint64, err error) | 62 IncrementExisting(key string, delta int64) (newValue uint64, err error) |
25 | 63 |
| 64 // Flush dumps the entire memcache state. |
26 Flush() error | 65 Flush() error |
27 | 66 |
| 67 // Stats gets some best-effort statistics about the current state of mem
cache. |
28 Stats() (*Statistics, error) | 68 Stats() (*Statistics, error) |
| 69 |
| 70 Raw() RawInterface |
29 } | 71 } |
OLD | NEW |