Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitOnce ¶
func InitOnce(conf CacheConfig)
InitOnce inits cache service configuration only once.
Types ¶
type CacheConfig ¶
type CacheConfig struct {
// local cache flush time.
FlushTimerTime time.Duration
// local cache cleanup time.
CleanupInterval time.Duration
// local cache expiration time.
DefaultExpiration time.Duration
}
CacheConfig sets for cache service daemon.
type CacheFlushDaemon ¶
type CacheFlushDaemon interface {
// Done tells the cache service quit this cache flush daemon.
Done(ctx context.Context) (done <-chan interface{})
// LoadKeys loads keys with current value by cache daemon setting.
LoadKeys(ctx context.Context, value interface{}) (cacheKeys []string)
// LoadValues loads values by cache daemon setting.
LoadValues(ctx context.Context) (values []interface{})
}
CacheFlushDaemon represents a flush daemon will be registered, should do implement of all methods.
type CacheService ¶
type CacheService interface {
// Set a pair of key-value to cache map.
Set(k string, v interface{})
// SetEx a pair of key-value to cache map by expiration.
SetEx(k string, v interface{}, ex time.Duration)
// Get the value by key from cache map.
Get(k string) (v interface{}, ok bool)
// Del a pair key-value by key.
Del(k string)
// GetKeys gets all keys for cache map.
GetKeys() []string
// GetValues gets all values for cache map.
GetValues() []interface{}
// GetByDefault gets the value by key, if it does not exist key then return default value.
GetByDefault(k string, v interface{}) interface{}
// Item gets all items from cache map.
Item() map[string]cache.Item
// Flush clears the cache map.
Flush()
// Register registers a CacheFlushDaemon to cache service,
// cache service will flush the cache by ticker time.
Register(ctx context.Context, daemon CacheFlushDaemon)
}
CacheService represents a cache service interface, package for go-cache.
Set a pair of key-value to cache map.
Get the value by key from cache map.
Register registers a CacheFlushDaemon to cache service, cache service will flush the cache by ticker time.
func Singleton ¶
func Singleton() CacheService
Singleton creates a cache service singleton by lazy mode.
Click to show internal directories.
Click to hide internal directories.