Decrement an item of type int64 by n. Returns an error if the item's value is not an int64, or if it was not found. If there is no error, the decremented value is returned.
(k string, n int64)
| 725 | // not an int64, or if it was not found. If there is no error, the decremented |
| 726 | // value is returned. |
| 727 | func (c *cache) DecrementInt64(k string, n int64) (int64, error) { |
| 728 | c.mu.Lock() |
| 729 | v, found := c.items[k] |
| 730 | if !found || v.Expired() { |
| 731 | c.mu.Unlock() |
| 732 | return 0, fmt.Errorf("Item %s not found", k) |
| 733 | } |
| 734 | rv, ok := v.Object.(int64) |
| 735 | if !ok { |
| 736 | c.mu.Unlock() |
| 737 | return 0, fmt.Errorf("The value for %s is not an int64", k) |
| 738 | } |
| 739 | nv := rv - n |
| 740 | v.Object = nv |
| 741 | c.items[k] = v |
| 742 | c.mu.Unlock() |
| 743 | return nv, nil |
| 744 | } |
| 745 | |
| 746 | // Decrement an item of type uint by n. Returns an error if the item's value is |
| 747 | // not an uint, or if it was not found. If there is no error, the decremented |