Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Capacity() int
- func (c *Cache) Contains(key KeyType) bool
- func (c *Cache) Get(key KeyType) (ValueType, bool)
- func (c *Cache) Len() int
- func (c *Cache) Purge()
- func (c *Cache) Query(key KeyType) (value ValueType, ok bool)
- func (c *Cache) Remove(key KeyType) bool
- func (c *Cache) Set(key KeyType, value ValueType) (evicted bool)
- type CtorConfig
- type KeyType
- type ValueAllocationFunc
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func New ¶
func New(config CtorConfig) *Cache
func (*Cache) Get ¶
查询缓存中是否存在 key, 存在则 ok = true,并返回 value 不存在,则尝试调用初始化函数生成 value 并存入缓存中,存入成功,也会返回 true
type CtorConfig ¶
type CtorConfig struct { Capacity int AllocFunc ValueAllocationFunc }
type ValueAllocationFunc ¶
Click to show internal directories.
Click to hide internal directories.