Documentation
¶
Index ¶
- Variables
- func BufferMarshal(result interface{}) ([]byte, error)
- func BufferUnmarshal(data []byte, result interface{}) error
- func CPUTicks() int64
- func FastRand() uint32
- func MemHash(data []byte) uint64
- func MemHashString(str string) uint64
- func Memclr(b []byte)
- func NanoTime() int64
- func NewRing(params RingCacheParams, opts ...CacheOption) *ringCache
- type Cache
- func (c *Cache) Add(key Key, value interface{}, ttl ...time.Duration)
- func (c *Cache) Get(key Key) (value interface{}, ok bool)
- func (c *Cache) Keys() []Key
- func (c *Cache) Len() int
- func (c *Cache) Peek(key Key) (interface{}, bool)
- func (c *Cache) Remove(key Key)
- func (c *Cache) TTL(key Key) time.Duration
- type CacheOption
- type Key
- type L2Cache
- type L2CacheOption
- type RingCacheParams
- type SlowCache
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidType = errors.New("invalid type")
ErrInvalidType is the error of invalid type
var ErrIsNil = errors.New("cache is nil")
ErrIsNil is the error of nil cache
Functions ¶
func BufferMarshal ¶ added in v0.3.2
BufferMarshal converts *bytes.Buffer to bytes, it returns a ErrInvalidType if restult is not *bytes.Buffer
func BufferUnmarshal ¶ added in v0.3.2
BufferUnmarshal writes the data to buffer, it returns a ErrInvalidType if restult is not *bytes.Buffer
func CPUTicks ¶ added in v0.5.0
func CPUTicks() int64
CPUTicks is a faster alternative to NanoTime to measure time duration.
func FastRand ¶ added in v0.5.0
func FastRand() uint32
FastRand is a fast thread local random function.
func MemHash ¶ added in v0.5.0
MemHash is the hash function used by go map, it utilizes available hardware instructions(behaves as aeshash if aes instruction is available). NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash.
func MemHashString ¶ added in v0.5.0
MemHashString is the hash function used by go map, it utilizes available hardware instructions (behaves as aeshash if aes instruction is available). NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash.
func NanoTime ¶ added in v0.5.0
func NanoTime() int64
NanoTime returns the current time in nanoseconds from a monotonic clock.
func NewRing ¶ added in v0.5.0
func NewRing(params RingCacheParams, opts ...CacheOption) *ringCache
NewRing returns a new ring cache
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func New ¶
func New(maxEntries int, defaultTTL time.Duration, opts ...CacheOption) *Cache
New returns a new lru cache with ttl
func (*Cache) Get ¶
Get returns value and exists from the cache by key, if value is expired then remove it. If the value is expired, value is not nil but exists is false.
func (*Cache) Peek ¶ added in v0.4.0
Peek get a key's value from the cache, but not move to front. The performance is better than get. It will not remove it if the cache is expired.
type CacheOption ¶ added in v0.4.1
type CacheOption func(c *Cache)
CacheOption cache option
func CacheEvictedOption ¶ added in v0.4.1
func CacheEvictedOption(fn func(key Key, value interface{})) CacheOption
CacheEvictedOption sets evicted function to cache
type L2Cache ¶ added in v0.3.0
type L2Cache struct {
// contains filtered or unexported fields
}
func NewL2Cache ¶ added in v0.3.0
func NewL2Cache(slowCache SlowCache, maxEntries int, defaultTTL time.Duration, opts ...L2CacheOption) *L2Cache
NewL2Cache return a new L2Cache, it returns panic if maxEntries or defaultTTL is nil
func (*L2Cache) Get ¶ added in v0.3.0
Get first get cache from lru, if not exists, then get the data from slow cache. Use unmarshal function covert the data to result
type L2CacheOption ¶ added in v0.4.1
type L2CacheOption func(c *L2Cache)
L2CacheOption l2cache option
func L2CacheMarshalOption ¶ added in v0.4.1
func L2CacheMarshalOption(fn func(v interface{}) ([]byte, error)) L2CacheOption
L2CacheMarshalOption set custom marshal function for l2cache
func L2CachePrefixOption ¶ added in v0.4.1
func L2CachePrefixOption(prefix string) L2CacheOption
L2CachePrefixOption set prefix for l2cache
func L2CacheUnmarshalOption ¶ added in v0.4.1
func L2CacheUnmarshalOption(fn func(data []byte, v interface{}) error) L2CacheOption
L2CacheUnmarshalOption set custom unmarshal function for l2cache