* add siteID to cache Get * indirect option setters * add mongo cache with tests, add Key and Flusher * lint: minor warns * workaround for cache parallel test * repeater in mongo cache * missing repeater vendor * fix nop cache * add cache mongo benchmark * wired mongo cache, single opts group for mongo * disable goconst * stop cache repeated on not found error * use local mongo for tests in travis
36 lines
982 B
Go
36 lines
982 B
Go
package cache
|
|
|
|
// Option func type
|
|
type Option func(lc cacheWithOpts) error
|
|
|
|
// MaxValSize functional option defines the largest value's size allowed to be cached
|
|
// By default it is 0, which means unlimited.
|
|
func MaxValSize(max int) Option {
|
|
return func(lc cacheWithOpts) error {
|
|
return lc.setMaxValSize(max)
|
|
}
|
|
}
|
|
|
|
// MaxKeys functional option defines how many keys to keep.
|
|
// By default it is 0, which means unlimited.
|
|
func MaxKeys(max int) Option {
|
|
return func(lc cacheWithOpts) error {
|
|
return lc.setMaxKeys(max)
|
|
}
|
|
}
|
|
|
|
// MaxCacheSize functional option defines the total size of cached data.
|
|
// By default it is 0, which means unlimited.
|
|
func MaxCacheSize(max int64) Option {
|
|
return func(lc cacheWithOpts) error {
|
|
return lc.setMaxCacheSize(max)
|
|
}
|
|
}
|
|
|
|
// PostFlushFn functional option defines how callback function called after each Flush.
|
|
func PostFlushFn(postFlushFn func()) Option {
|
|
return func(lc cacheWithOpts) error {
|
|
return lc.setPostFlushFn(postFlushFn)
|
|
}
|
|
}
|