Documentation ¶
Overview ¶
Package cache provide a key-value data store with ttl interface.
Index ¶
- Variables
- func Factories() []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) Collection(prefix string) *Collection
- func (c *Cache) DefualtTTL() 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, error)
- 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) 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) Node(prefix string) *Node
- 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) Collection(prefix string) *Collection
- func (c *Collection) DefualtTTL() 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, error)
- 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) 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) Locker(key string) (*Locker, bool)
- 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) Marshal(v interface{}) ([]byte, error)
- func (c *Collection) Node(prefix string) *Node
- 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) Unmarshal(bytes []byte, v interface{}) error
- func (c *Collection) Update(key string, v interface{}, TTL time.Duration) error
- func (c *Collection) UpdateBytesValue(key string, bytes []byte, TTL time.Duration) error
- type Config
- type ConfigJSON
- type ConfigMap
- 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 Node
- func (n *Node) Collection(prefix string) *Collection
- func (n *Node) DefualtTTL() 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, error)
- 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 (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) Locker(key string) (*Locker, bool)
- func (n *Node) MGetBytesValue(keys ...string) (map[string][]byte, error)
- func (n *Node) MSetBytesValue(data map[string][]byte, ttl time.Duration) error
- func (n *Node) Marshal(v interface{}) ([]byte, error)
- 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) Unmarshal(bytes []byte, v interface{}) error
- func (n *Node) Update(key string, v interface{}, TTL time.Duration) error
- func (n *Node) UpdateBytesValue(key string, bytes []byte, TTL time.Duration) error
- type Option
- type OptionConfig
- type OptionConfigJSON
- type OptionConfigMap
- 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") //ErrPermanentCacheNotSupport raised when cache driver not support permanent ttl. ErrPermanentCacheNotSupport = errors.New("Permanent cache is not supported.can use ttl <0 on this cache") )
var CollectionTTLMultiple = 10
CollectionTTLMultiple default collection ttl multiple
var DefaultMarshaler = "msgpack"
DefaultMarshaler default marshaler name
var DefualtTTL = time.Duration(0)
DefualtTTL means use cache default ttl setting.
var ( //KeyPrefix default key prefix KeyPrefix = string([]byte{0}) )
var TTLForever = time.Duration(-1)
TTLForever When cache ttl sets to TTLForever,the cache will never expire.
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 ¶
NewSubCache create subcache with given config and prefix. Return cache created and any error if raised.
func (*Cache) Collection ¶
func (c *Cache) Collection(prefix string) *Collection
Collection get a cache colletion with given prefix
func (*Cache) DefualtTTL ¶
DefualtTTL 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 DefualtTTL(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 DefualtTTL(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 DefualtTTL(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 DefualtTTL(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 DefualtTTL(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 { //Set Set data model to cache by given key. //If ttl is DefualtTTL(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 DefualtTTL(0),use default ttl in config instead. //Return any error raised. Update(key string, v interface{}, ttl time.Duration) error //SetBytesValue Set bytes data to cache by given key. //If ttl is DefualtTTL(0),use default ttl in config instead. //Return any error raised. SetBytesValue(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) //UpdateBytesValue Update bytes data to cache by given key only if the cache exist. //If ttl is DefualtTTL(0),use default ttl in config instead. //Return any error raised. UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error //Del Delete data in cache by given name. //Return any error raised. Del(key string) error //Expire set cache value expire duration by given key and ttl Expire(key string, ttl time.Duration) error //IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. //If ttl is DefualtTTL(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 DefualtTTL(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 //ExpireCounter set cache counter expire duration by given key and ttl ExpireCounter(key string, 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 DefualtTTL(0),use default ttl in config instead. //Return any error raised. Load(key string, v interface{}, ttl time.Duration, loader Loader) 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 //FinalKey get final key which passed to cache driver . FinalKey(string) (string, error) //Flush Delete all data in cache. Flush() error //DefualtTTL return cache default ttl DefualtTTL() time.Duration // Locker return locker by given key Locker(key string) (*Locker, bool) //Marshal Marshal data model to bytes. //Return marshaled bytes and any error rasied. Marshal(v interface{}) ([]byte, error) //Unmarshal Unmarshal bytes to data model. //Parameter v should be pointer to empty data model which data filled in. //Return any error raseid. Unmarshal(bytes []byte, v interface{}) error }
Cacheable interface which can be used as cache.
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) Collection ¶
func (c *Collection) Collection(prefix string) *Collection
Collection get a cache colletion with given prefix
func (*Collection) DefualtTTL ¶
func (c *Collection) DefualtTTL() time.Duration
DefualtTTL 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, error)
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 DefualtTTL(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 DefualtTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) Locker ¶
func (c *Collection) Locker(key string) (*Locker, bool)
Locker create new locker with given key. return locker and if locker aleady locked
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) Marshal ¶
func (c *Collection) Marshal(v interface{}) ([]byte, error)
Marshal Marshal data model to bytes. Return marshaled bytes and any error rasied.
func (*Collection) Node ¶
func (c *Collection) Node(prefix string) *Node
Node get a cache node 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 DefualtTTL(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 DefualtTTL(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 DefualtTTL(0),use default ttl in config instead. Return any error raised.
func (*Collection) Unmarshal ¶
func (c *Collection) 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.
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 DefualtTTL(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 DefualtTTL(0),use default ttl in config instead. Return any error raised.
type ConfigJSON ¶
ConfigJSON config in json format.
func (*ConfigJSON) Get ¶
func (c *ConfigJSON) Get(key string, v interface{}) error
Get get value from config json. Return any error if raised.
func (*ConfigJSON) Set ¶
func (c *ConfigJSON) Set(key string, v interface{}) error
Set set value to config json. Return any error if raised.
type ConfigMap ¶
type ConfigMap map[string]interface{}
ConfigMap config in map format.
type Driver ¶
type Driver interface { Util() *Util SetUtil(*Util) SetBytesValue(key string, bytes []byte, ttl time.Duration) error //Set bytes data to cache by given key. UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error //Update bytes data to cache by given key only if the cache exist. GetBytesValue(key string) ([]byte, error) //Get bytes data from cache by given key. Del(key string) error //Delete data in cache by given key. IncrCounter(key string, increment int64, ttl time.Duration) (int64, error) //Increase int val in cache by given key.Count cache and data cache are in two independent namespace. SetCounter(key string, v int64, ttl time.Duration) error //Set int val in cache by given key.Count cache and data cache are in two independent namespace. GetCounter(key string) (int64, error) //Get int val from cache by given key.Count cache and data cache are in two independent namespace. DelCounter(key string) error //Delete int val in cache by given key.Count cache and data cache are in two independent namespace. SetGCErrHandler(f func(err error)) //Set callback to handler error raised when gc. Expire(key string, ttl time.Duration) error ExpireCounter(key string, ttl time.Duration) error MGetBytesValue(keys ...string) (map[string][]byte, error) MSetBytesValue(map[string][]byte, time.Duration) error Close() error //Close cache. Flush() error //Delete all data in cache. }
Driver : Cache driver interface.Should Never used directly
func MustNewDriver ¶
MustNewDriver create new dirver with given driver name,config and prefix. 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 config and prefix 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 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) DefualtTTL ¶
DefualtTTL 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 DefualtTTL(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 DefualtTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) Locker ¶
Locker create new locker with given key. return locker and if locker aleady locked
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) Marshal ¶
Marshal Marshal data model to bytes. Return marshaled bytes and any error rasied.
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 DefualtTTL(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 DefualtTTL(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 DefualtTTL(0),use default ttl in config instead. Return any error raised.
func (*Node) 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 OptionConfig ¶
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 OptionConfigJSON ¶
type OptionConfigJSON struct { Driver string TTL int64 Marshaler string Config ConfigJSON }
OptionConfigJSON option config in json format
func (*OptionConfigJSON) ApplyTo ¶
func (o *OptionConfigJSON) ApplyTo(c *Cache) error
ApplyTo apply config json option to cache. Return any error if raised.
type OptionConfigMap ¶
OptionConfigMap option config in map format.
func (*OptionConfigMap) ApplyTo ¶
func (o *OptionConfigMap) ApplyTo(c *Cache) error
ApplyTo apply config map option to cache. Return any error if raised.
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. |
gocache
Package gocache provides cache driver uses memory to store cache data.
|
Package gocache 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
|
|
Package session is used to store user data in token based cache.
|
Package session is used to store user data in token based cache. |