Documentation
¶
Overview ¶
Package cache providers a cache management for baa.
Index ¶
- Constants
- func Register(name string, f instanceFunc)
- func SimpleType(v interface{}) bool
- func SimpleValue(v []byte, o interface{}) bool
- type Cacher
- type Item
- type ItemBinary
- type Memory
- func (c *Memory) Decr(key string) (int64, error)
- func (c *Memory) Delete(key string) error
- func (c *Memory) Exist(key string) bool
- func (c *Memory) Flush() error
- func (c *Memory) Get(key string, out interface{}) error
- func (c *Memory) Incr(key string) (int64, error)
- func (c *Memory) Set(key string, v interface{}, ttl int64) error
- func (c *Memory) Start(o Options) error
- type Options
Constants ¶
View Source
const ( // MemoryLimit default memory size limit, 128mb // 128 1 << 7 // 1024 1 << 10 MemoryLimit int64 = 1 << 27 // MemoryLimitMin minimum value for memory limit, 1mb MemoryLimitMin int64 = 1 << 20 // MenoryObjectMaxSize maximum bytes for object, 1mb MenoryObjectMaxSize int64 = 1 << 20 )
Variables ¶
This section is empty.
Functions ¶
func SimpleType ¶
func SimpleType(v interface{}) bool
SimpleType check value type is simple type or not
func SimpleValue ¶
SimpleValue return value to output with type convert
Types ¶
type Cacher ¶
type Cacher interface {
// Exist return true if value cached by given key
Exist(key string) bool
// Get returns value to out by given key
Get(key string, out interface{}) error
// Set cache value by given key, cache ttl second
Set(key string, v interface{}, ttl int64) error
// Incr increases cached int-type value by given key as a counter
// if key not exist, before increase set value with zero
Incr(key string) (int64, error)
// Decr decreases cached int-type value by given key as a counter
// if key not exist, before increase set value with zero
// NOTE: memcached returns uint type cannot be less than zero
Decr(key string) (int64, error)
// Delete delete cached data by given key
Delete(key string) error
// Flush flush cacher
Flush() error
// Start new a cacher and start service
Start(Options) error
}
Cacher a cache management for baa
type Item ¶
type Item struct {
Val interface{} // real object value
TTL int64 // cache life time
Expiration int64 // expired time
}
Item cache storage item
func (*Item) Encode ¶
func (t *Item) Encode() (ItemBinary, error)
Encode encode item to bytes by gob
type ItemBinary ¶
type ItemBinary []byte
ItemBinary cache item encoded data
func (ItemBinary) Item ¶
func (t ItemBinary) Item() (*Item, error)
Item decode bytes data to cache item use gob
type Memory ¶
Memory implement a memory cache adapter for cacher
func (*Memory) Decr ¶
Decr decreases cached int-type value by given key as a counter if key not exist, return errors
func (*Memory) Incr ¶
Incr increases cached int-type value by given key as a counter if key not exist, before increase set value with zero
Click to show internal directories.
Click to hide internal directories.