Documentation ¶
Index ¶
- Variables
- func Adapters() []string
- func Config() *ini.File
- func Decr(val interface{}) (interface{}, error)
- func HasAdapter(name string) bool
- func Incr(val interface{}) (interface{}, error)
- func Register(name string, adapter Cache)
- func Version() string
- type Cache
- type Codec
- type FileCacher
- func (c *FileCacher) Client() interface{}
- func (c *FileCacher) Close() error
- func (c *FileCacher) Codec() encoding.Codec
- func (c *FileCacher) Decr(key string) error
- func (c *FileCacher) Delete(key string) error
- func (c *FileCacher) Flush() error
- func (c *FileCacher) Get(key string, value interface{}) error
- func (c *FileCacher) Incr(key string) error
- func (c *FileCacher) IsExist(key string) bool
- func (c *FileCacher) Put(key string, val interface{}, expire int64) error
- func (c *FileCacher) SetCodec(codec encoding.Codec)
- func (c *FileCacher) StartAndGC(opt Options) error
- type GetAs
- func (g GetAs) Any(key string) interface{}
- func (g GetAs) Bytes(key string) []byte
- func (g GetAs) Float32(key string) float32
- func (g GetAs) Float64(key string) float64
- func (g GetAs) Int(key string) int
- func (g GetAs) Int32(key string) int32
- func (g GetAs) Int64(key string) int64
- func (g GetAs) Map(key string) map[string]interface{}
- func (g GetAs) Mapx(key string) param.Store
- func (g GetAs) Slice(key string) []interface{}
- func (g GetAs) String(key string) string
- func (g GetAs) Uint(key string) uint
- func (g GetAs) Uint32(key string) uint32
- func (g GetAs) Uint64(key string) uint64
- type Getter
- type Item
- type MemoryCacher
- func (c *MemoryCacher) Client() interface{}
- func (c *MemoryCacher) Close() error
- func (c *MemoryCacher) Codec() encoding.Codec
- func (c *MemoryCacher) Decr(key string) (err error)
- func (c *MemoryCacher) Delete(key string) error
- func (c *MemoryCacher) Flush() error
- func (c *MemoryCacher) Get(key string, value interface{}) error
- func (c *MemoryCacher) Incr(key string) (err error)
- func (c *MemoryCacher) IsExist(key string) bool
- func (c *MemoryCacher) Put(key string, val interface{}, expire int64) error
- func (c *MemoryCacher) SetCodec(codec encoding.Codec)
- func (c *MemoryCacher) StartAndGC(opt Options) error
- type MemoryItem
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrExpired = errors.New("expired") ErrNotSupported = errors.New("not supported operation") )
var DefaultCodec encoding.Codec = msgpack.MsgPack
Functions ¶
func HasAdapter ¶
Types ¶
type Cache ¶
type Cache interface { // Put puts value into cache with key and expire time. Put(key string, val interface{}, timeout int64) error // Get gets cached value by given key. Get(key string, value interface{}) error // Delete deletes cached value by given key. Delete(key string) error // Incr increases cached int-type value by given key as a counter. Incr(key string) error // Decr decreases cached int-type value by given key as a counter. Decr(key string) error // IsExist returns true if cached value exists. IsExist(key string) bool // Flush deletes all cached data. Flush() error // StartAndGC starts GC routine based on config string settings. StartAndGC(opt Options) error Close() error Client() interface{} Codec Getter }
Cache is the interface that operates the cache data.
func Cacher ¶
Cacher is a middleware that maps a cache.Cache service into the Macaron handler chain. An single variadic cache.Options struct can be optionally provided to configure.
func NewCacher ¶
NewCacher creates and returns a new cacher by given adapter name and configuration. It panics when given adapter isn't registered and starts GC automatically.
func NewMemoryCacher ¶
func NewMemoryCacher() Cache
NewMemoryCacher creates and returns a new memory cacher.
type FileCacher ¶
type FileCacher struct { GetAs // contains filtered or unexported fields }
FileCacher represents a file cache adapter implementation.
func NewFileCacher ¶
func NewFileCacher() *FileCacher
NewFileCacher creates and returns a new file cacher.
func (*FileCacher) Client ¶
func (c *FileCacher) Client() interface{}
func (*FileCacher) Close ¶
func (c *FileCacher) Close() error
func (*FileCacher) Codec ¶
func (c *FileCacher) Codec() encoding.Codec
func (*FileCacher) Delete ¶
func (c *FileCacher) Delete(key string) error
Delete deletes cached value by given key.
func (*FileCacher) Get ¶
func (c *FileCacher) Get(key string, value interface{}) error
Get gets cached value by given key.
func (*FileCacher) Incr ¶
func (c *FileCacher) Incr(key string) error
Incr increases cached int-type value by given key as a counter.
func (*FileCacher) IsExist ¶
func (c *FileCacher) IsExist(key string) bool
IsExist returns true if cached value exists.
func (*FileCacher) Put ¶
func (c *FileCacher) Put(key string, val interface{}, expire int64) error
Put puts value into cache with key and expire time. If expired is 0, it will be deleted by next GC operation.
func (*FileCacher) SetCodec ¶
func (c *FileCacher) SetCodec(codec encoding.Codec)
func (*FileCacher) StartAndGC ¶
func (c *FileCacher) StartAndGC(opt Options) error
StartAndGC starts GC routine based on config string settings.
type Getter ¶
type Getter interface { String(key string) string Int(key string) int Uint(key string) uint Int64(key string) int64 Uint64(key string) uint64 Int32(key string) int32 Uint32(key string) uint32 Float32(key string) float32 Float64(key string) float64 Bytes(key string) []byte Map(key string) map[string]interface{} Any(key string) interface{} Mapx(key string) param.Store Slice(key string) []interface{} }
type MemoryCacher ¶
type MemoryCacher struct { GetAs // contains filtered or unexported fields }
MemoryCacher represents a memory cache adapter implementation.
func (*MemoryCacher) Client ¶
func (c *MemoryCacher) Client() interface{}
func (*MemoryCacher) Close ¶
func (c *MemoryCacher) Close() error
func (*MemoryCacher) Codec ¶
func (c *MemoryCacher) Codec() encoding.Codec
func (*MemoryCacher) Decr ¶
func (c *MemoryCacher) Decr(key string) (err error)
Decr decreases cached int-type value by given key as a counter.
func (*MemoryCacher) Delete ¶
func (c *MemoryCacher) Delete(key string) error
Delete deletes cached value by given key.
func (*MemoryCacher) Get ¶
func (c *MemoryCacher) Get(key string, value interface{}) error
Get gets cached value by given key.
func (*MemoryCacher) Incr ¶
func (c *MemoryCacher) Incr(key string) (err error)
Incr increases cached int-type value by given key as a counter.
func (*MemoryCacher) IsExist ¶
func (c *MemoryCacher) IsExist(key string) bool
IsExist returns true if cached value exists.
func (*MemoryCacher) Put ¶
func (c *MemoryCacher) Put(key string, val interface{}, expire int64) error
Put puts value into cache with key and expire time. If expired is 0, it will be deleted by next GC operation.
func (*MemoryCacher) SetCodec ¶
func (c *MemoryCacher) SetCodec(codec encoding.Codec)
func (*MemoryCacher) StartAndGC ¶
func (c *MemoryCacher) StartAndGC(opt Options) error
StartAndGC starts GC routine based on config string settings.
type MemoryItem ¶
type MemoryItem struct {
// contains filtered or unexported fields
}
MemoryItem represents a memory cache item.
type Options ¶
type Options struct { // Name of adapter. Default is "memory". Adapter string // Adapter configuration, it's corresponding to adapter. AdapterConfig string // GC interval time in seconds. Default is 60. Interval int // Occupy entire database. Default is false. OccupyMode bool // Configuration section name. Default is "cache". Section string }
Options represents a struct for specifying configuration options for the cache middleware.