Even better spacing
This commit is contained in:
parent
783e6df827
commit
e68e585c61
89
README
89
README
@ -53,11 +53,10 @@ Usage:
|
||||
...
|
||||
}
|
||||
|
||||
If you store a reference type like a pointer, slice, map or channel, you do not need to
|
||||
run Set if you modify the underlying data. The cache does not serialize its data, so if
|
||||
you modify a struct whose pointer you've stored in the cache, retrieving that pointer
|
||||
with Get will point you to the same data:
|
||||
|
||||
// If you store a reference type like a pointer, slice, map or channel, you do not need to
|
||||
// run Set if you modify the underlying data. The cache does not serialize its data, so if
|
||||
// you modify a struct whose pointer you've stored in the cache, retrieving that pointer
|
||||
// with Get will point you to the same data:
|
||||
foo := &MyStruct{Num: 1}
|
||||
c.Set("foo", foo, 0)
|
||||
...
|
||||
@ -71,58 +70,58 @@ with Get will point you to the same data:
|
||||
foo := x.(MyStruct)
|
||||
foo.Println(foo.Num)
|
||||
|
||||
will print:
|
||||
// will print:
|
||||
1
|
||||
2
|
||||
|
||||
Reference:
|
||||
|
||||
func New(de, ci time.Duration) *Cache
|
||||
Returns a new cache with a given default expiration duration and default cleanup
|
||||
interval. If the expiration duration is less than 1, the items in the cache never
|
||||
expire and must be deleted manually. If the cleanup interval is less than one,
|
||||
expired items are not deleted from the cache before their next lookup or before
|
||||
calling DeleteExpired.
|
||||
func New(de, ci time.Duration) *Cache
|
||||
Returns a new cache with a given default expiration duration and default cleanup
|
||||
interval. If the expiration duration is less than 1, the items in the cache never
|
||||
expire and must be deleted manually. If the cleanup interval is less than one,
|
||||
expired items are not deleted from the cache before their next lookup or before
|
||||
calling DeleteExpired.
|
||||
|
||||
func (c *Cache) Set(k string, x interface{}, d time.Duration)
|
||||
Adds an item to the cache, replacing any existing item. If the duration is 0, the
|
||||
cache's default expiration time is used. If it is -1, the item never expires.
|
||||
func (c *Cache) Set(k string, x interface{}, d time.Duration)
|
||||
Adds an item to the cache, replacing any existing item. If the duration is 0, the
|
||||
cache's default expiration time is used. If it is -1, the item never expires.
|
||||
|
||||
func (c *Cache) Add(k string, x interface{}, d time.Duration) error
|
||||
Adds an item to the cache only if an item doesn't already exist for the given key,
|
||||
or if the existing item has expired. Returns an error if not.
|
||||
func (c *Cache) Add(k string, x interface{}, d time.Duration) error
|
||||
Adds an item to the cache only if an item doesn't already exist for the given key,
|
||||
or if the existing item has expired. Returns an error if not.
|
||||
|
||||
func (c *Cache) Replace(k string, x interface{}, d time.Duration) error
|
||||
Sets a new value for the cache item only if it already exists. Returns an error if
|
||||
it does not.
|
||||
func (c *Cache) Replace(k string, x interface{}, d time.Duration) error
|
||||
Sets a new value for the cache item only if it already exists. Returns an error if
|
||||
it does not.
|
||||
|
||||
func (c *Cache) Get(k string) (interface{}, bool)
|
||||
Gets an item from the cache. Returns the item or nil, and a bool indicating whether
|
||||
the given key was found in the cache.
|
||||
func (c *Cache) Get(k string) (interface{}, bool)
|
||||
Gets an item from the cache. Returns the item or nil, and a bool indicating whether
|
||||
the given key was found in the cache.
|
||||
|
||||
func (c *Cache) Increment(k string, n int64) error
|
||||
Increment 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 increment it
|
||||
by n. Passing a negative number will cause the item to be decremented.
|
||||
func (c *Cache) Increment(k string, n int64) error
|
||||
Increment 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 increment it
|
||||
by n. Passing a negative number will cause the item to be decremented.
|
||||
|
||||
func (c *Cache) IncrementFloat(k string, n float64) error
|
||||
Increment an item of type int, int8, int16, int32, int64, uintptr, uint, uint8,
|
||||
uint32, 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 increment it by
|
||||
n. Passing a negative number will cause the item to be decremented.
|
||||
func (c *Cache) IncrementFloat(k string, n float64) error
|
||||
Increment an item of type int, int8, int16, int32, int64, uintptr, uint, uint8,
|
||||
uint32, 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 increment it by
|
||||
n. Passing a negative number will cause the item to be decremented.
|
||||
|
||||
func (c *Cache) Decrement(k string, n int64) error
|
||||
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.
|
||||
func (c *Cache) Decrement(k string, n int64) error
|
||||
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.
|
||||
|
||||
func (c *Cache) Delete(k string)
|
||||
Deletes an item from the cache. Does nothing if the item does not exist in the cache.
|
||||
func (c *Cache) Delete(k string)
|
||||
Deletes an item from the cache. Does nothing if the item does not exist in the cache.
|
||||
|
||||
func (c *Cache) DeleteExpired()
|
||||
Deletes all expired items from the cache.
|
||||
func (c *Cache) DeleteExpired()
|
||||
Deletes all expired items from the cache.
|
||||
|
||||
func (c *Cache) Flush()
|
||||
Deletes all items from the cache.
|
||||
func (c *Cache) Flush()
|
||||
Deletes all items from the cache.
|
||||
|
Loading…
Reference in New Issue
Block a user