Documentation
¶
Overview ¶
Package cache provide a key-value data store with ttl interface.
Index ¶
- Variables
- func Factories() []string
- func Key(key string) string
- func MarshalerFactories() []string
- func NewRandMaskedBytes(mask []byte, length int, origin []byte) ([]byte, error)
- func NewRandomBytes(length int, origin []byte) ([]byte, error)
- func RandMaskedBytes(mask []byte, length int) ([]byte, error)
- func RandomBytes(length int) ([]byte, error)
- func Register(name string, f Factory)
- func RegisterMarshaler(name string, f MarshalerFactory)
- func UnregisterAll()
- func UnregisterAllMarshalers()
- type Cache
- func (c *Cache) DefaultTTL() time.Duration
- func (c *Cache) Del(key string) error
- func (c *Cache) DelCounter(key string) error
- func (c *Cache) Expire(key string, ttl time.Duration) error
- func (c *Cache) ExpireCounter(key string, ttl time.Duration) error
- func (c *Cache) Field(fieldname string) *Field
- func (c *Cache) FinalKey(key string) string
- func (c *Cache) Get(key string, v interface{}) error
- func (c *Cache) GetBytesValue(key string) ([]byte, error)
- func (c *Cache) GetCounter(key string) (int64, error)
- func (c *Cache) Hit() int64
- func (c *Cache) IncrCounter(key string, increment int64, ttl time.Duration) (int64, error)
- func (c *Cache) Init(option Option) error
- func (c *Cache) Load(key string, v interface{}, ttl time.Duration, loader Loader) error
- func (c *Cache) Locker(key string) (*Locker, bool)
- func (c *Cache) MGetBytesValue(keys ...string) (map[string][]byte, error)
- func (c *Cache) MSetBytesValue(data map[string][]byte, ttl time.Duration) error
- func (c *Cache) Marshal(v interface{}) ([]byte, error)
- func (c *Cache) Miss() int64
- func (c *Cache) Proxy(prefix string) *Proxy
- func (c *Cache) Set(key string, v interface{}, ttl time.Duration) error
- func (c *Cache) SetBytesValue(key string, bytes []byte, ttl time.Duration) error
- func (c *Cache) SetCounter(key string, v int64, ttl time.Duration) error
- func (c *Cache) Unmarshal(bytes []byte, v interface{}) error
- func (c *Cache) Update(key string, v interface{}, ttl time.Duration) error
- func (c *Cache) UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error
- type Cacheable
- type Collection
- func (c *Collection) Close() error
- func (c *Collection) DefaultTTL() time.Duration
- func (c *Collection) Del(key string) error
- func (c *Collection) DelCounter(key string) error
- func (c *Collection) Expire(key string, TTL time.Duration) error
- func (c *Collection) ExpireCounter(key string, TTL time.Duration) error
- func (c *Collection) Field(fieldname string) *Field
- func (c *Collection) FinalKey(key string) string
- func (c *Collection) Flush() error
- func (c *Collection) Get(key string, v interface{}) error
- func (c *Collection) GetBytesValue(key string) ([]byte, error)
- func (c *Collection) GetCacheKey(key string) (string, error)
- func (c *Collection) GetCounter(key string) (int64, error)
- func (c *Collection) Hit() int64
- func (c *Collection) IncrCounter(key string, increment int64, TTL time.Duration) (int64, error)
- func (c *Collection) Load(key string, v interface{}, TTL time.Duration, loader Loader) error
- func (c *Collection) MGetBytesValue(keys ...string) (map[string][]byte, error)
- func (c *Collection) MSetBytesValue(data map[string][]byte, ttl time.Duration) error
- func (c *Collection) Miss() int64
- func (c *Collection) Proxy(prefix string) *Proxy
- func (c *Collection) Set(key string, v interface{}, TTL time.Duration) error
- func (c *Collection) SetBytesValue(key string, bytes []byte, TTL time.Duration) error
- func (c *Collection) SetCounter(key string, v int64, TTL time.Duration) error
- func (c *Collection) SetUtil(u *Util)
- func (c *Collection) Update(key string, v interface{}, TTL time.Duration) error
- func (c *Collection) UpdateBytesValue(key string, bytes []byte, TTL time.Duration) error
- func (c *Collection) Util() *Util
- type Driver
- type DriverUtil
- type DummyCache
- func (c *DummyCache) Close() error
- func (c *DummyCache) Del(key string) error
- func (c *DummyCache) DelCounter(key string) error
- func (c *DummyCache) Expire(key string, ttl time.Duration) error
- func (c *DummyCache) ExpireCounter(key string, ttl time.Duration) error
- func (c *DummyCache) Flush() error
- func (c *DummyCache) GetBytesValue(key string) ([]byte, error)
- func (c *DummyCache) GetCounter(key string) (int64, error)
- func (c *DummyCache) IncrCounter(key string, increment int64, ttl time.Duration) (int64, error)
- func (c *DummyCache) MGetBytesValue(keys ...string) (map[string][]byte, error)
- func (c *DummyCache) MSetBytesValue(data map[string][]byte, ttl time.Duration) error
- func (c *DummyCache) SetBytesValue(key string, bytes []byte, ttl time.Duration) error
- func (c *DummyCache) SetCounter(key string, v int64, ttl time.Duration) error
- func (c *DummyCache) SetGCErrHandler(f func(err error))
- func (c *DummyCache) UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error
- type Factory
- type Field
- func (f *Field) Del() error
- func (f *Field) DelCounter() error
- func (f *Field) Get(v interface{}) error
- func (f *Field) GetBytesValue() ([]byte, error)
- func (f *Field) GetCounter() (int64, error)
- func (f *Field) IncrCounter(increment int64, ttl time.Duration) (int64, error)
- func (f *Field) Set(v interface{}, ttl time.Duration) error
- func (f *Field) SetBytesValue(bytes []byte, ttl time.Duration) error
- func (f *Field) SetCounter(v int64, ttl time.Duration) error
- func (f *Field) Update(v interface{}, ttl time.Duration) error
- func (f *Field) UpdateBytesValue(bytes []byte, ttl time.Duration) error
- type JSONMarshaler
- type Loader
- type Locker
- type Marshaler
- type MarshalerFactory
- type MinimumOperation
- type Node
- func (n *Node) Close() error
- func (n *Node) Collection(prefix string) *Collection
- func (n *Node) DefaultTTL() time.Duration
- func (n *Node) Del(key string) error
- func (n *Node) DelCounter(key string) error
- func (n *Node) Expire(key string, ttl time.Duration) error
- func (n *Node) ExpireCounter(key string, ttl time.Duration) error
- func (n *Node) Field(fieldname string) *Field
- func (n *Node) FinalKey(key string) string
- func (n *Node) Flush() error
- func (n *Node) Get(key string, v interface{}) error
- func (n *Node) GetBytesValue(key string) ([]byte, error)
- func (n *Node) GetCacheKey(key string) (string, error)
- func (n *Node) GetCounter(key string) (int64, error)
- func (c *Node) Hit() int64
- func (n *Node) IncrCounter(key string, increment int64, ttl time.Duration) (int64, error)
- func (n *Node) Load(key string, v interface{}, TTL time.Duration, loader Loader) error
- func (n *Node) MGetBytesValue(keys ...string) (map[string][]byte, error)
- func (n *Node) MSetBytesValue(data map[string][]byte, ttl time.Duration) error
- func (c *Node) Miss() int64
- func (n *Node) MustGetCacheKey(key string) string
- func (n *Node) Node(prefix string) *Node
- func (n *Node) Set(key string, v interface{}, ttl time.Duration) error
- func (n *Node) SetBytesValue(key string, bytes []byte, ttl time.Duration) error
- func (n *Node) SetCounter(key string, v int64, ttl time.Duration) error
- func (n *Node) SetUtil(u *Util)
- func (n *Node) Update(key string, v interface{}, TTL time.Duration) error
- func (n *Node) UpdateBytesValue(key string, bytes []byte, TTL time.Duration) error
- func (n *Node) Util() *Util
- type Option
- type OptionConfig
- type Proxy
- type Util
Constants ¶
This section is empty.
Variables ¶
var ( //ErrNotFound raised when the given data not found in cache. ErrNotFound = errors.New("Entry not found") //ErrNotCacheable raised if the data cannot be cached. ErrNotCacheable = errors.New("Not Cachable") //ErrEntryTooLarge raised when data is too large to store. ErrEntryTooLarge = errors.New("Entry too large to cache") //ErrKeyTooLarge raised when key is too large to store. ErrKeyTooLarge = errors.New("Key too large to cache") ErrKeyUnavailable = errors.New("Key Unavailable") //ErrFeatureNotSupported raised when calling feature on unsupported driver. ErrFeatureNotSupported = errors.New("Feature is not supported") //ErrTTLNotAvaliable raised when ttl not avaliable. ErrTTLNotAvaliable = errors.New("TTL not avaliable") )
var CollectionTTLMultiple = 10
CollectionTTLMultiple default collection ttl multiple
var DefaultMarshaler = "msgpack"
DefaultMarshaler default marshaler name
var DefaultTTL = time.Duration(0)
DefaultTTL means use cache default ttl setting.
var ( //KeyPrefix default key prefix KeyPrefix = string([]byte{0}) )
var TokenMask = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.")
TokenMask The []bytes of alphabet and number to generate token.
Functions ¶
func Factories ¶
func Factories() []string
Factories returns a sorted list of the names of the registered factories.
func MarshalerFactories ¶
func MarshalerFactories() []string
MarshalerFactories returns a sorted list of the names of the registered marshaler factories.
func NewRandMaskedBytes ¶
NewRandMaskedBytes Generate a give length random []byte which different from origin bytes. All bytes in the random []byte is select from given mask. Return the random [] byte and any error raised.
func NewRandomBytes ¶
NewRandomBytes Generate a give length random []byte which different from origin bytes. Return the random [] byte and any error raised.
func RandMaskedBytes ¶
RandMaskedBytes Generate a give length random []byte. All bytes in the random []byte is select from given mask. Return the random [] byte and any error raised.
func RandomBytes ¶
RandomBytes Generate a give length random []byte. Return the random [] byte and any error raised.
func Register ¶
Register makes a driver creator available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.
func RegisterMarshaler ¶
func RegisterMarshaler(name string, f MarshalerFactory)
RegisterMarshaler makes a marshaler creator available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.
func UnregisterAllMarshalers ¶
func UnregisterAllMarshalers()
UnregisterAllMarshalers Unregister all marshalers
Types ¶
type Cache ¶
Cache Cache stores the cache Driver and default ttl.
func NewSubCache ¶
func NewSubCache(conf *OptionConfig) (*Cache, error)
NewSubCache create subcache with given loader. Return cache created and any error if raised.
func (*Cache) DefaultTTL ¶
DefaultTTL return cache default ttl
func (*Cache) DelCounter ¶
DelCounter Delete int val in cache by given name.Count cache and data cache are in two independent namespace. Return any error raised.
func (*Cache) ExpireCounter ¶
ExpireCounter set cache counter expire duration by given key and ttl
func (*Cache) Get ¶
Get Get data model from cache by given key. Parameter v should be pointer to empty data model which data filled in. Return any error raised.
func (*Cache) GetBytesValue ¶
GetBytesValue Get bytes data from cache by given key. Return data bytes and any error raised.
func (*Cache) GetCounter ¶
GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.
func (*Cache) IncrCounter ¶
IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. If ttl is DefaultTTL(0),use default ttl in config instead. Return int data value and any error raised.
func (*Cache) Load ¶
Load Get data model from cache by given key.If data not found,call loader to get current data value and save to cache. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Cache) Locker ¶
Locker create new locker with given key. return locker and if locker aleady locked.
func (*Cache) MGetBytesValue ¶
MGetBytesValue get multiple bytes data from cache by given keys. Return data bytes map and any error if raised.
func (*Cache) MSetBytesValue ¶
MSetBytesValue set multiple bytes data to cache with given key-value map. Return any error if raised.
func (*Cache) Marshal ¶
Marshal Marshal data model to bytes. Return marshaled bytes and any error rasied.
func (*Cache) Set ¶
Set Set data model to cache by given key. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Cache) SetBytesValue ¶
SetBytesValue Set bytes data to cache by given key. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Cache) SetCounter ¶
SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Cache) Unmarshal ¶
Unmarshal Unmarshal bytes to data model. Parameter v should be pointer to empty data model which data filled in. Return any error raseid.
type Cacheable ¶
type Cacheable interface { MinimumOperation //Set Set data model to cache by given key. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return any error raised. Set(key string, v interface{}, ttl time.Duration) error //Get Get data model from cache by given key. //Parameter v should be pointer to empty data model which data filled in. //Return any error raised. Get(key string, v interface{}) error //Update Update data model to cache by given key only if the cache exist. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return any error raised. Update(key string, v interface{}, ttl time.Duration) error //Load Get data model from cache by given key.If data not found,call loader to get current data value and save to cache. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return any error raised. Load(key string, v interface{}, ttl time.Duration, loader Loader) error //FinalKey get final key which passed to cache driver . FinalKey(string) string //DefaultTTL return cache default ttl DefaultTTL() time.Duration Hit() int64 Miss() int64 }
Cacheable interface which can be used as cache.
func NewNestedCollection ¶
NewNestedCollection create new nested cache collection with given cache,prefix. Return collection created.
type Collection ¶
type Collection struct { //Cache raw cache Cache Cacheable //Prefix cache key prefix Prefix string // default ttl TTL time.Duration }
Collection cache Collection Collection is flushable sub cache create from other cacheable.
func NewCollection ¶
func NewCollection(cache Cacheable, prefix string, TTL time.Duration) *Collection
NewCollection create new cache collection with given cache,prefix and ttl. Return collection created.
func (*Collection) DefaultTTL ¶
func (c *Collection) DefaultTTL() time.Duration
DefaultTTL return cache default ttl
func (*Collection) Del ¶
func (c *Collection) Del(key string) error
Del Delete data in cache by given name. Return any error raised.
func (*Collection) DelCounter ¶
func (c *Collection) DelCounter(key string) error
DelCounter Delete int val in cache by given name.Count cache and data cache are in two independent namespace. Return any error raised.
func (*Collection) Expire ¶
func (c *Collection) Expire(key string, TTL time.Duration) error
Expire set cache value expire duration by given key and ttl
func (*Collection) ExpireCounter ¶
func (c *Collection) ExpireCounter(key string, TTL time.Duration) error
ExpireCounter set cache counter expire duration by given key and ttl
func (*Collection) Field ¶
func (c *Collection) Field(fieldname string) *Field
Field retuan a cache field with given field name
func (*Collection) FinalKey ¶
func (c *Collection) FinalKey(key string) string
FinalKey get final key which passed to cache driver .
func (*Collection) Get ¶
func (c *Collection) Get(key string, v interface{}) error
Get Get data model from cache by given key. Parameter v should be pointer to empty data model which data filled in. Return any error raised.
func (*Collection) GetBytesValue ¶
func (c *Collection) GetBytesValue(key string) ([]byte, error)
GetBytesValue Get bytes data from cache by given key. Return data bytes and any error raised.
func (*Collection) GetCacheKey ¶
func (c *Collection) GetCacheKey(key string) (string, error)
GetCacheKey return raw cache key by given key. Return key and any error if raised.
func (*Collection) GetCounter ¶
func (c *Collection) GetCounter(key string) (int64, error)
GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.
func (*Collection) IncrCounter ¶
IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. If ttl is DefaultTTL(0),use default ttl in config instead. Return int data value and any error raised.
func (*Collection) Load ¶
Load Get data model from cache by given key.If data not found,call loader to get current data value and save to cache. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) MGetBytesValue ¶
func (c *Collection) MGetBytesValue(keys ...string) (map[string][]byte, error)
MGetBytesValue get multiple bytes data from cache by given keys. Return data bytes map and any error if raised.
func (*Collection) MSetBytesValue ¶
MSetBytesValue set multiple bytes data to cache with given key-value map. Return any error if raised.
func (*Collection) Proxy ¶
func (c *Collection) Proxy(prefix string) *Proxy
Proxy get a cache proxy with given prefix
func (*Collection) Set ¶
func (c *Collection) Set(key string, v interface{}, TTL time.Duration) error
Set Set data model to cache by given key. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) SetBytesValue ¶
SetBytesValue Set bytes data to cache by given key. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) SetCounter ¶
SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) SetUtil ¶
func (c *Collection) SetUtil(u *Util)
func (*Collection) Update ¶
func (c *Collection) Update(key string, v interface{}, TTL time.Duration) error
Update Update data model to cache by given key only if the cache exist. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) UpdateBytesValue ¶
UpdateBytesValue Update bytes data to cache by given key only if the cache exist. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) Util ¶
func (c *Collection) Util() *Util
type Driver ¶
type Driver interface { MinimumOperation //Set callback to handler error raised when gc. SetGCErrHandler(f func(err error)) }
Driver : Cache driver interface.Should Never used directly
func MustNewDriver ¶
MustNewDriver create new dirver with given driver name and loader. Return driver created. Painc is any error raised.
type DriverUtil ¶
type DriverUtil struct {
// contains filtered or unexported fields
}
DriverUtil drive util struct.
type DummyCache ¶
type DummyCache struct {
DriverUtil
}
DummyCache DummyCache dont store any data. Usually used in develop environment or testing
func (*DummyCache) Close ¶
func (c *DummyCache) Close() error
Close Close cache. Return any error if raised
func (*DummyCache) Del ¶
func (c *DummyCache) Del(key string) error
Del Delete data in cache by given key. Return any error raised.
func (*DummyCache) DelCounter ¶
func (c *DummyCache) DelCounter(key string) error
DelCounter Delete int val in cache by given key.Count cache and data cache are in two independent namespace. Return any error raised.
func (*DummyCache) Expire ¶
func (c *DummyCache) Expire(key string, ttl time.Duration) error
Expire set cache value expire duration by given key and ttl
func (*DummyCache) ExpireCounter ¶
func (c *DummyCache) ExpireCounter(key string, ttl time.Duration) error
ExpireCounter set cache counter expire duration by given key and ttl
func (*DummyCache) Flush ¶
func (c *DummyCache) Flush() error
Flush Delete all data in cache. Return any error if raised
func (*DummyCache) GetBytesValue ¶
func (c *DummyCache) GetBytesValue(key string) ([]byte, error)
GetBytesValue Get bytes data from cache by given key. Return data bytes and any error raised.
func (*DummyCache) GetCounter ¶
func (c *DummyCache) GetCounter(key string) (int64, error)
GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.
func (*DummyCache) IncrCounter ¶
IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.
func (*DummyCache) MGetBytesValue ¶
func (c *DummyCache) MGetBytesValue(keys ...string) (map[string][]byte, error)
MGetBytesValue get multiple bytes data from cache by given keys. Return data bytes map and any error if raised.
func (*DummyCache) MSetBytesValue ¶
MSetBytesValue set multiple bytes data to cache with given key-value map. Return any error if raised.
func (*DummyCache) SetBytesValue ¶
SetBytesValue Set bytes data to cache by given key. Return any error raised.
func (*DummyCache) SetCounter ¶
SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace. Return any error raised.
func (*DummyCache) SetGCErrHandler ¶
func (c *DummyCache) SetGCErrHandler(f func(err error))
SetGCErrHandler Set callback to handler error raised when gc.
func (*DummyCache) UpdateBytesValue ¶
UpdateBytesValue Update bytes data to cache by given key only if the cache exist. Return any error raised.
type Factory ¶
Factory create driver with given loader. Reutrn driver created and any error if raised..
type Field ¶
Field cache field component
func (*Field) DelCounter ¶
DelCounter delete field counter. Return any error if raised.
func (*Field) GetBytesValue ¶
GetBytesValue get bytes value from field Return bytes value and any error if raised.
func (*Field) GetCounter ¶
GetCounter get field counter. Return counter value and any error if raised.
func (*Field) IncrCounter ¶
IncrCounter incr field counter with given increment and ttl Return new counter value and any error if raised.
func (*Field) SetBytesValue ¶
SetBytesValue set bytes to field with given ttl. Return any error if raised.
func (*Field) SetCounter ¶
SetCounter set field counter with given value and ttl. Return any error if raised.
type JSONMarshaler ¶
type JSONMarshaler struct { }
JSONMarshaler Marshaler which marshal data as JSON format
func (*JSONMarshaler) Marshal ¶
func (m *JSONMarshaler) Marshal(v interface{}) ([]byte, error)
Marshal Marshal data model to bytes. Return marshaled bytes and any erro rasied.
func (*JSONMarshaler) Unmarshal ¶
func (m *JSONMarshaler) Unmarshal(bytes []byte, v interface{}) error
Unmarshal Unmarshal bytes to data model. Parameter v should be pointer to empty data model which data filled in. Return any error raseid.
type Loader ¶
Loader cache value loader used in cache load method. Load value with given key. Return loaded value and any error if raised.
type Marshaler ¶
type Marshaler interface { Marshal(v interface{}) ([]byte, error) Unmarshal(bytes []byte, v interface{}) error }
Marshaler Marshaler inteface
func NewMarshaler ¶
NewMarshaler create new marshaler with given name. Return marshaler created and any error if raised.
type MarshalerFactory ¶
MarshalerFactory create marshaler. Reutrn marshaler created and any error if raised..
type MinimumOperation ¶
type MinimumOperation interface { Util() *Util SetUtil(*Util) //SetBytesValue Set bytes data to cache by given key. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return any error raised. SetBytesValue(key string, bytes []byte, ttl time.Duration) error //UpdateBytesValue Update bytes data to cache by given key only if the cache exist. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return any error raised. UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error //GetBytesValue Get bytes data from cache by given key. //Return data bytes and any error raised. GetBytesValue(key string) ([]byte, error) //Del Delete data in cache by given name. //Return any error raised. Del(key string) error //IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return int data value and any error raised. IncrCounter(key string, increment int64, ttl time.Duration) (int64, error) //SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace. //If ttl is DefaultTTL(0),use default ttl in config instead. //Return any error raised. SetCounter(key string, v int64, ttl time.Duration) error //GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace. //Return int data value and any error raised. GetCounter(key string) (int64, error) //DelCounter Delete int val in cache by given name.Count cache and data cache are in two independent namespace. //Return any error raised. DelCounter(key string) error //Expire set cache value expire duration by given key and ttl //Return any error raised. Expire(key string, ttl time.Duration) error //ExpireCounter set cache counter expire duration by given key and ttl ExpireCounter(key string, ttl time.Duration) error //MGetBytesValue get multiple bytes data from cache by given keys. //Return data bytes map and any error if raised. MGetBytesValue(keys ...string) (map[string][]byte, error) //MSetBytesValue set multiple bytes data to cache with given key-value map. //Return any error if raised. MSetBytesValue(map[string][]byte, time.Duration) error //Close close cache. Close() error //Flush Delete all data in cache. Flush() error }
type Node ¶
Node cache Collection Node is Permanent-able sub cache create from other cacheable.
func (*Node) Collection ¶
func (n *Node) Collection(prefix string) *Collection
Collection get a cache colletion with given prefix
func (*Node) DefaultTTL ¶
DefaultTTL return cache default ttl
func (*Node) DelCounter ¶
DelCounter Delete int val in cache by given name.Count cache and data cache are in two independent namespace. Return any error raised.
func (*Node) ExpireCounter ¶
ExpireCounter set cache counter expire duration by given key and ttl
func (*Node) Get ¶
Get Get data model from cache by given key. Parameter v should be pointer to empty data model which data filled in. Return any error raised.
func (*Node) GetBytesValue ¶
GetBytesValue Get bytes data from cache by given key. Return data bytes and any error raised.
func (*Node) GetCacheKey ¶
GetCacheKey return raw cache key by given key. Return key and any error if raised.
func (*Node) GetCounter ¶
GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.
func (*Node) IncrCounter ¶
IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. If ttl is DefaultTTL(0),use default ttl in config instead. Return int data value and any error raised.
func (*Node) Load ¶
Load Get data model from cache by given key.If data not found,call loader to get current data value and save to cache. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) MGetBytesValue ¶
MGetBytesValue get multiple bytes data from cache by given keys. Return data bytes map and any error if raised.
func (*Node) MSetBytesValue ¶
MSetBytesValue set multiple bytes data to cache with given key-value map. Return any error if raised.
func (*Node) MustGetCacheKey ¶
MustGetCacheKey return raw cache key by given key. Return key. Panic if any error raised.
func (*Node) Set ¶
Set Set data model to cache by given key. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) SetBytesValue ¶
SetBytesValue Set bytes data to cache by given key. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) SetCounter ¶
SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) Update ¶
Update Update data model to cache by given key only if the cache exist. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) UpdateBytesValue ¶
UpdateBytesValue Update bytes data to cache by given key only if the cache exist. If ttl is DefaultTTL(0),use default ttl in config instead. Return any error raised.
type OptionConfig ¶
type OptionConfig struct { Driver string TTL int64 Marshaler string Config func(v interface{}) error `config:", lazyload"` }
OptionConfig cache option
func NewOptionConfig ¶
func NewOptionConfig() *OptionConfig
NewOptionConfig create new cache option.
func (*OptionConfig) ApplyTo ¶
func (o *OptionConfig) ApplyTo(cache *Cache) error
ApplyTo apply option to given cache. Return any error if raised.
type Util ¶
type Util struct { Marshaler Marshaler // contains filtered or unexported fields }
Util cache util
func (*Util) Locker ¶
Locker create new locker with given key. Return locker and if locker is locked.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
drivers
|
|
cachegroup
Package cachegroup provides a cache drive which combined with give caches driver.
|
Package cachegroup provides a cache drive which combined with give caches driver. |
freecache
Package freecache provides cache driver uses memory to store cache data.
|
Package freecache provides cache driver uses memory to store cache data. |
syncmapcache
Package syncmapcache provides cache driver uses sync.map to store cache data.
|
Package syncmapcache provides cache driver uses sync.map to store cache data. |
marshalers
|
|