cache.go
func (c *cache) Decrement(k string, n int64) error {
	// TODO: Implement Increment and Decrement more cleanly.
	// (Cannot do Increment(k, n*-1) for uints.)
	c.mu.Lock()
	v, found := c.items[k]
	if !found || v.Expired() {
		c.mu.Unlock()
		return fmt.Errorf("Item not found")
	}
	switch v.Object.(type) {
	case int:
		v.Object = v.Object.(int) - int(n)
	case int8:
		v.Object = v.Object.(int8) - int8(n)
	case int16:
		v.Object = v.Object.(int16) - int16(n)
	case int32:
		v.Object = v.Object.(int32) - int32(n)
	case int64:
		v.Object = v.Object.(int64) - n
	case uint:
		v.Object = v.Object.(uint) - uint(n)
	case uintptr:
		v.Object = v.Object.(uintptr) - uintptr(n)
	case uint8:
		v.Object = v.Object.(uint8) - uint8(n)
	case uint16:
		v.Object = v.Object.(uint16) - uint16(n)
	case uint32:
		v.Object = v.Object.(uint32) - uint32(n)
	case uint64:
		v.Object = v.Object.(uint64) - uint64(n)
	case float32:
		v.Object = v.Object.(float32) - float32(n)
	case float64:
		v.Object = v.Object.(float64) - float64(n)
	default:
		c.mu.Unlock()
		return fmt.Errorf("The value for %s is not an integer", k)
	}
	c.items[k] = v
	c.mu.Unlock()
	return nil
}
func (c *cache) Decrement(k string, n int64) error {
	// TODO: Implement Increment and Decrement more cleanly.
	// (Cannot do Increment(k, n*-1) for uints.)
	c.mu.Lock()
	v, found := c.items[k]
	if !found || v.Expired() {
		c.mu.Unlock()
		return fmt.Errorf("Item not found")
	}
	switch v.Object.(type) {
	case int:
		v.Object = v.Object.(int) - int(n)
	case int8:
		v.Object = v.Object.(int8) - int8(n)
	case int16:
		v.Object = v.Object.(int16) - int16(n)
	case int32:
		v.Object = v.Object.(int32) - int32(n)
	case int64:
		v.Object = v.Object.(int64) - n
	case uint:
		v.Object = v.Object.(uint) - uint(n)
	case uintptr:
		v.Object = v.Object.(uintptr) - uintptr(n)
	case uint8:
		v.Object = v.Object.(uint8) - uint8(n)
	case uint16:
		v.Object = v.Object.(uint16) - uint16(n)
	case uint32:
		v.Object = v.Object.(uint32) - uint32(n)
	case uint64:
		v.Object = v.Object.(uint64) - uint64(n)
	case float32:
		v.Object = v.Object.(float32) - float32(n)
	case float64:
		v.Object = v.Object.(float64) - float64(n)
	default:
		c.mu.Unlock()
		return fmt.Errorf("The value for %s is not an integer", k)
	}
	c.items[k] = v
	c.mu.Unlock()
	return nil
}
func ( c * cache ) Decrement ( k string , n int64 ) error { // TODO: Implement Increment and Decrement more cleanly. // (Cannot do Increment(k, n*-1) for uints.) c . mu . Lock ( ) v , found := c . items [ k ] if ! found || v . Expired ( ) { c . mu . Unlock ( ) return fmt . Errorf ( " " ) } switch v . Object . ( type ) { case int : v . Object = v . Object . ( int ) - int ( n ) case int8 : v . Object = v . Object . ( int8 ) - int8 ( n ) case int16 : v . Object = v . Object . ( int16 ) - int16 ( n ) case int32 : v . Object = v . Object . ( int32 ) - int32 ( n ) case int64 : v . Object = v . Object . ( int64 ) - n case uint : v . Object = v . Object . ( uint ) - uint ( n ) case uintptr : v . Object = v . Object . ( uintptr ) - uintptr ( n ) case uint8 : v . Object = v . Object . ( uint8 ) - uint8 ( n ) case uint16 : v . Object = v . Object . ( uint16 ) - uint16 ( n ) case uint32 : v . Object = v . Object . ( uint32 ) - uint32 ( n ) case uint64 : v . Object = v . Object . ( uint64 ) - uint64 ( n ) case float32 : v . Object = v . Object . ( float32 ) - float32 ( n ) case float64 : v . Object = v . Object . ( float64 ) - float64 ( n ) default : c . mu . Unlock ( ) return fmt . Errorf ( " " , k ) } c . items [ k ] = v c . mu . Unlock ( ) return nil }
// Decrement an item of type int, int8, int16, int32, int64, uintptr, uint,
// uint8, uint32, or uint64, float32 or float64 by n. Returns an error if the
// item's value is not an integer, if it was not found, or if it is not
// possible to decrement it by n. To retrieve the decremented value, use one
// of the specialized methods, e.g. DecrementInt64.
Decrement an item of type int int8 int16 int32 int64 uintptr uint uint8 uint32 or uint64 float32 or float64 by n . Returns an error if the item s value is not an integer if it was not found or if it is not possible to decrement it by n . To retrieve the decremented value use one of the specialized methods e . g . DecrementInt64 .