Documentation
¶
Index ¶
- Constants
- type Cache
- func (c Cache) Add(k string, x interface{}, d time.Duration) error
- func (c Cache) Decrement(k string, n int64) error
- func (c Cache) DecrementFloat(k string, n float64) error
- func (c Cache) DecrementFloat32(k string, n float32) (float32, error)
- func (c Cache) DecrementFloat64(k string, n float64) (float64, error)
- func (c Cache) DecrementInt(k string, n int) (int, error)
- func (c Cache) DecrementInt8(k string, n int8) (int8, error)
- func (c Cache) DecrementInt16(k string, n int16) (int16, error)
- func (c Cache) DecrementInt32(k string, n int32) (int32, error)
- func (c Cache) DecrementInt64(k string, n int64) (int64, error)
- func (c Cache) DecrementUint(k string, n uint) (uint, error)
- func (c Cache) DecrementUint8(k string, n uint8) (uint8, error)
- func (c Cache) DecrementUint16(k string, n uint16) (uint16, error)
- func (c Cache) DecrementUint32(k string, n uint32) (uint32, error)
- func (c Cache) DecrementUint64(k string, n uint64) (uint64, error)
- func (c Cache) DecrementUintptr(k string, n uintptr) (uintptr, error)
- func (c Cache) Delete(k string)
- func (c Cache) DeleteExpired()
- func (c Cache) Flush()
- func (c Cache) Get(k string) (interface{}, bool)
- func (c Cache) GetWithExpiration(k string) (interface{}, time.Time, bool)
- func (c Cache) Increment(k string, n int64) error
- func (c Cache) IncrementFloat(k string, n float64) error
- func (c Cache) IncrementFloat32(k string, n float32) (float32, error)
- func (c Cache) IncrementFloat64(k string, n float64) (float64, error)
- func (c Cache) IncrementInt(k string, n int) (int, error)
- func (c Cache) IncrementInt8(k string, n int8) (int8, error)
- func (c Cache) IncrementInt16(k string, n int16) (int16, error)
- func (c Cache) IncrementInt32(k string, n int32) (int32, error)
- func (c Cache) IncrementInt64(k string, n int64) (int64, error)
- func (c Cache) IncrementUint(k string, n uint) (uint, error)
- func (c Cache) IncrementUint8(k string, n uint8) (uint8, error)
- func (c Cache) IncrementUint16(k string, n uint16) (uint16, error)
- func (c Cache) IncrementUint32(k string, n uint32) (uint32, error)
- func (c Cache) IncrementUint64(k string, n uint64) (uint64, error)
- func (c Cache) IncrementUintptr(k string, n uintptr) (uintptr, error)
- func (c Cache) ItemCount() int
- func (c Cache) Items() map[string]Item
- func (c Cache) Load(r io.Reader) error
- func (c Cache) LoadFile(fname string) error
- func (c Cache) OnEvicted(f func(string, interface{}))
- func (c Cache) Replace(k string, x interface{}, d time.Duration) error
- func (c Cache) Save(w io.Writer) (err error)
- func (c Cache) SaveFile(fname string) error
- func (c Cache) Set(k string, x interface{}, d time.Duration)
- func (c Cache) SetDefault(k string, x interface{})
- type Item
Constants ¶
const ( // NoExpiration 用于需要过期时间的函数,永不过期 NoExpiration time.Duration = -1 // DefaultExpiration 用于需要过期时间的函数。相当于传递与创建缓存时提供给 New() 或 NewFrom() 的相同过期时间(例如 5 分钟)。 DefaultExpiration time.Duration = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func New ¶
New 返回指定默认过期时间和清理间隔的新缓存。 如果过期时间小于 1(或 NoExpiration),则缓存中的项目永不过期(默认情况下),必须手动删除。 如果清理间隔小于 1,则在调用 c.DeleteExpired() 之前,不会从缓存中删除过期的项目。
func NewFrom ¶
NewFrom 返回指定默认过期时间和清理间隔的新缓存。 如果过期时间小于 1(或 NoExpiration),则缓存中的项目永不过期(默认情况下),必须手动删除。 如果清理间隔小于 1,则在调用 c.DeleteExpired() 之前,不会从缓存中删除过期的项目。
还接受将用作缓存的基础映射的项目映射。 这对于从反序列化缓存(c.Items() 序列化使用 gob.encode() ),或者传入(例如make(map[string]Item, 500)) 以提高缓存预期达到某个最小大小时的性能。
只有缓存的方法会同步对此映射的访问,因此不建议在创建缓存后保留对映射的任何引用。如果需要,可以在以后使用 c.Items 访问(受相同警告的约束)。
关于序列化的注意事项:使用 gob 时,请确保使用 gob.Register() 在对使用 c.Items() 检索到的映射进行编码之前存储在缓存中的单个类型,并在解码包含项目映射的 blob 之前注册这些相同的类型。
func (Cache) Decrement ¶
Decrement 将类型为 int、int8、int16、int32、int64、uintptr、uint、uint8、uint32 、 uint64、float32 、 float64 的项目减 n。
func (Cache) DecrementFloat ¶
DecrementFloat float类型的值递减 n
func (Cache) DecrementFloat32 ¶
DecrementFloat32 float32类型的值递减 n
func (Cache) DecrementFloat64 ¶
DecrementFloat64 float64类型的值递减 n
func (Cache) DecrementInt ¶
DecrementInt int类型的值递减 n
func (Cache) DecrementInt8 ¶
DecrementInt8 Int8类型的值递减 n
func (Cache) DecrementInt16 ¶
DecrementInt16 int16类型的值递减 n
func (Cache) DecrementInt32 ¶
DecrementInt32 int32类型的值递减 n
func (Cache) DecrementInt64 ¶
DecrementInt64 int64类型的值递减 n
func (Cache) DecrementUint ¶
DecrementUint uint类型的值递减 n
func (Cache) DecrementUint8 ¶
DecrementUint8 uint8类型的值递减 n
func (Cache) DecrementUint16 ¶
DecrementUint16 uint16类型的值递减 n
func (Cache) DecrementUint32 ¶
DecrementUint32 uint32类型的值递减 n
func (Cache) DecrementUint64 ¶
DecrementUint64 uint64类型的值递减 n
func (Cache) DecrementUintptr ¶
DecrementUintptr uintptr类型的值递减 n
func (Cache) GetWithExpiration ¶
GetWithExpiration 从缓存中返回一个项目及其过期时间。返回项目或 nil,如果设置了过期时间(如果项目永不过期,时间为0。),以及是否找到key的布尔值。
func (Cache) Increment ¶
Increment 将类型为 int、int8、int16、int32、int64、uintptr、uint、uint8、uint32 、 uint64、float32 、 float64 的项目递增 n。 如果key的值不是整数、找不到key的值或无法按 n 递增,则返回错误。 要检索递增的值,请使用专用方法,例如 IncrementInt64。
func (Cache) IncrementFloat ¶
IncrementFloat 将 float32 或 float64 类型的项目递增 n。 如果key的值不是浮点型、找不到浮点型或无法将其递增 n 时,则返回错误。 传递负数以减小该值。要检索递增的值,请使用专用方法,例如 IncrementFloat64。
func (Cache) IncrementFloat32 ¶
IncrementFloat32 float32类型的值递增 n
func (Cache) IncrementFloat64 ¶
IncrementFloat64 float64类型的值递增 n
func (Cache) IncrementInt ¶
IncrementInt int类型的值递增 n
func (Cache) IncrementInt8 ¶
IncrementInt8 int8类型的值递增 n
func (Cache) IncrementInt16 ¶
IncrementInt16 int16类型的值递增 n
func (Cache) IncrementInt32 ¶
IncrementInt32 int32类型的值递增 n
func (Cache) IncrementInt64 ¶
IncrementInt64 int64类型的值递增 n
func (Cache) IncrementUint ¶
IncrementUint uint类型的值递增 n
func (Cache) IncrementUint8 ¶
IncrementUint8 uint8类型的值递增 n
func (Cache) IncrementUint16 ¶
IncrementUint16 uint16类型的值递增 n
func (Cache) IncrementUint32 ¶
IncrementUint32 uint32类型的值递增 n
func (Cache) IncrementUint64 ¶
IncrementUint64 uint64类型的值递增 n
func (Cache) IncrementUintptr ¶
IncrementUintptr uintptr类型的值递增 n
func (Cache) Load ¶
Load 从io.Reader中读取Gob序列化缓存项目。不包括当前缓存中的项目。 注:此方法已弃用以支持c.Items() 和 NewFrom()(参考 NewFrom() 描述)
func (Cache) LoadFile ¶
LoadFile 从指定的文件中读取已保存的项目,不包含已缓存的项目。 注:此方法已弃用以支持c.Items() 和 NewFrom()(参考 NewFrom() 描述)
func (Cache) OnEvicted ¶
func (c Cache) OnEvicted(f func(string, interface{}))
OnEvicted 设置一个(可选)函数,当从缓存中逐出项时,该函数与键和值一起调用。(包括手动删除时,但不包括覆盖时。设置为 nil 表示禁用。
func (Cache) SaveFile ¶
SaveFile 将缓存的项目保存到指定的文件,如果文件不存在,则创建该文件,如果存在,则覆盖该文件。 注:此方法已弃用以支持c.Items() 和 NewFrom()(参考 NewFrom() 描述)
func (Cache) SetDefault ¶
func (c Cache) SetDefault(k string, x interface{})
SetDefault 使用默认过期时间将项目添加到缓存,替换已项目。