Documentation ¶
Overview ¶
Package golayeredcache implements a Golang multi-level caching framework based on Redis and local memory for distributed scenarios.
See https://github.com/begonia-org/go-layered-cache for more information about go-layered-cache.
Index ¶
- func DecodeFromBytes(src []byte, dst interface{}) error
- func EncodeToBytes(src interface{}) ([]byte, error)
- type BaseLayeredCacheImpl
- func (lc *BaseLayeredCacheImpl) Del(ctx context.Context, key interface{}, args ...interface{}) error
- func (lc *BaseLayeredCacheImpl) DelOnLocal(ctx context.Context, key interface{}, args ...interface{}) error
- func (lc *BaseLayeredCacheImpl) Dump(ctx context.Context, key interface{}, args ...interface{}) <-chan interface{}
- func (lc *BaseLayeredCacheImpl) Get(ctx context.Context, key interface{}, args ...interface{}) ([]interface{}, error)
- func (lc *BaseLayeredCacheImpl) GetFromLocal(ctx context.Context, key interface{}, args ...interface{}) ([]interface{}, error)
- func (lc *BaseLayeredCacheImpl) Load(ctx context.Context, key interface{}, args ...interface{}) error
- func (lc *BaseLayeredCacheImpl) Scan(ctx context.Context, pattern string, onScan source.OnScan) <-chan error
- func (lc *BaseLayeredCacheImpl) Set(ctx context.Context, key interface{}, args ...interface{}) error
- func (lc *BaseLayeredCacheImpl) SetStrategy(strategy CacheReadStrategy)
- func (lc *BaseLayeredCacheImpl) SetToLocal(ctx context.Context, key interface{}, args ...interface{}) error
- func (lc *BaseLayeredCacheImpl) UnWatch() error
- func (lc *BaseLayeredCacheImpl) Watch(ctx context.Context, onMessage source.OnMessage) <-chan error
- type Cache
- type CacheOptions
- type CacheReadStrategy
- type LayeredBloomFilter
- func (lc *LayeredBloomFilter) Add(ctx context.Context, key string, value []byte) error
- func (lc *LayeredBloomFilter) AddLocalFilter(key string, filter local.Filter) error
- func (lc *LayeredBloomFilter) Check(ctx context.Context, key string, value []byte) (bool, error)
- func (lb *LayeredBloomFilter) LoadDump(ctx context.Context) error
- func (lb *LayeredBloomFilter) OnMessage(ctx context.Context, from string, message interface{}) error
- func (lc *LayeredBloomFilter) UnWatch() error
- func (lc *LayeredBloomFilter) Watch(ctx context.Context) <-chan error
- type LayeredBuildOptions
- type LayeredCache
- type LayeredCuckooFilter
- type LayeredCuckooFilterImpl
- func (lc *LayeredCuckooFilterImpl) Add(ctx context.Context, key string, value []byte) error
- func (lc *LayeredCuckooFilterImpl) AddLocalFilter(key string, filter local.Filter) error
- func (lc *LayeredCuckooFilterImpl) Check(ctx context.Context, key string, value []byte) (bool, error)
- func (lc *LayeredCuckooFilterImpl) Del(ctx context.Context, key string, value []byte) error
- func (lb *LayeredCuckooFilterImpl) LoadDump(ctx context.Context) error
- func (lb *LayeredCuckooFilterImpl) OnMessage(ctx context.Context, from string, message interface{}) error
- func (lc *LayeredCuckooFilterImpl) UnWatch() error
- func (lc *LayeredCuckooFilterImpl) Watch(ctx context.Context) <-chan error
- type LayeredCuckooFilterOptions
- type LayeredFilter
- type LayeredFilterOptions
- type LayeredKeyValueCache
- type LayeredKeyValueCacheImpl
- func (lc *LayeredKeyValueCacheImpl) Del(ctx context.Context, key string) error
- func (lc *LayeredKeyValueCacheImpl) Get(ctx context.Context, key string) ([]byte, error)
- func (lb *LayeredKeyValueCacheImpl) LoadDump(ctx context.Context) error
- func (lb *LayeredKeyValueCacheImpl) OnMessage(ctx context.Context, from string, message interface{}) error
- func (lc *LayeredKeyValueCacheImpl) Set(ctx context.Context, key string, value []byte, exp time.Duration) error
- func (lc *LayeredKeyValueCacheImpl) UnWatch() error
- func (lc *LayeredKeyValueCacheImpl) Watch(ctx context.Context) <-chan error
- type LayeredLocalCache
- type Loader
- type TypeEnum
- type Watcher
- type WithDelOperator
- type WithLayeredCuckooOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeFromBytes ¶
func EncodeToBytes ¶
Types ¶
type BaseLayeredCacheImpl ¶
type BaseLayeredCacheImpl struct {
// contains filtered or unexported fields
}
func (*BaseLayeredCacheImpl) Del ¶
func (lc *BaseLayeredCacheImpl) Del(ctx context.Context, key interface{}, args ...interface{}) error
func (*BaseLayeredCacheImpl) DelOnLocal ¶
func (lc *BaseLayeredCacheImpl) DelOnLocal(ctx context.Context, key interface{}, args ...interface{}) error
func (*BaseLayeredCacheImpl) Dump ¶
func (lc *BaseLayeredCacheImpl) Dump(ctx context.Context, key interface{}, args ...interface{}) <-chan interface{}
func (*BaseLayeredCacheImpl) Get ¶
func (lc *BaseLayeredCacheImpl) Get(ctx context.Context, key interface{}, args ...interface{}) ([]interface{}, error)
func (*BaseLayeredCacheImpl) GetFromLocal ¶
func (lc *BaseLayeredCacheImpl) GetFromLocal(ctx context.Context, key interface{}, args ...interface{}) ([]interface{}, error)
func (*BaseLayeredCacheImpl) Load ¶
func (lc *BaseLayeredCacheImpl) Load(ctx context.Context, key interface{}, args ...interface{}) error
func (*BaseLayeredCacheImpl) Set ¶
func (lc *BaseLayeredCacheImpl) Set(ctx context.Context, key interface{}, args ...interface{}) error
func (*BaseLayeredCacheImpl) SetStrategy ¶
func (lc *BaseLayeredCacheImpl) SetStrategy(strategy CacheReadStrategy)
func (*BaseLayeredCacheImpl) SetToLocal ¶
func (lc *BaseLayeredCacheImpl) SetToLocal(ctx context.Context, key interface{}, args ...interface{}) error
func (*BaseLayeredCacheImpl) UnWatch ¶
func (lc *BaseLayeredCacheImpl) UnWatch() error
type Cache ¶
type Cache struct { KV LayeredKeyValueCache Bloom LayeredFilter Cuckoo LayeredCuckooFilter }
type CacheBuildOptions func (cache *Cache) error
type CacheOptions ¶
type CacheReadStrategy ¶
type CacheReadStrategy int
const ( // Read from the local cache only LocalOnly CacheReadStrategy = iota // Read from the local cache first, then from the source cache LocalThenSource )
type LayeredBloomFilter ¶
type LayeredBloomFilter struct { *BaseLayeredCacheImpl // contains filtered or unexported fields }
func (*LayeredBloomFilter) AddLocalFilter ¶
func (lc *LayeredBloomFilter) AddLocalFilter(key string, filter local.Filter) error
func (*LayeredBloomFilter) LoadDump ¶
func (lb *LayeredBloomFilter) LoadDump(ctx context.Context) error
func (*LayeredBloomFilter) OnMessage ¶
func (lb *LayeredBloomFilter) OnMessage(ctx context.Context, from string, message interface{}) error
func (*LayeredBloomFilter) UnWatch ¶
func (lc *LayeredBloomFilter) UnWatch() error
type LayeredBuildOptions ¶
type LayeredBuildOptions struct { // RDB is the redis client as the source cache RDB *redis.Client // Watcher is the watch options for the source cache Watcher *source.WatchOptions // Log is the logger Log *logrus.Logger // Channel is the channel for the source cache // It is used to receive the message from the source cache // It is also used to publish the message to the source cache // In the case of the source cache is redis, it is the redis xstream channel Channel interface{} // KeyPrefix is the key prefix for cache,like "cache:test:bloom" KeyPrefix string // Strategy is the read strategy // It is used to determine the read strategy when the cache is read. // For Read from the local cache only, it is LocalOnly. // For Read from the local cache first, then from the source cache when the local cache is none, it is LocalThenSource Strategy CacheReadStrategy }
LayeredBuildOptions is the options for building the layered cache
type LayeredCache ¶
type LayeredCache interface { LayeredLocalCache // Get key value Get(ctx context.Context, key interface{}, args ...interface{}) ([]interface{}, error) Set(ctx context.Context, key interface{}, args ...interface{}) error Watch(ctx context.Context) <-chan error UnWatch() error // OnMessage is a callback function for the message from the source cache OnMessage(ctx context.Context, from string, message interface{}) error LoadDump(ctx context.Context) error }
LayeredCache is the interface for the layered cache
type LayeredCuckooFilter ¶
type LayeredCuckooFilter interface { LayeredFilter Del(ctx context.Context, key string, value []byte) error }
func NewLayeredCuckoo ¶
func NewLayeredCuckoo(options *LayeredBuildOptions, buildCuckooOptions gocuckoo.CuckooBuildOptions, extOptions ...LayeredFilterOptions) LayeredCuckooFilter
NewLayeredCuckoo creates a new LayeredCuckooFilter. It is only for cuckoo filter. The cuckoo filter is a layered cache, which means it has a local cuckoo filter cache and a redis cuckoo filter cache.
Parameters:
- options: LayeredBuildOptions is a struct that contains the options for building the layered cache.
- buildCuckooOptions: gocuckoo.CuckooBuildOptions is the configuration for the local cuckoo filter.
Returns:
- LayeredCuckooFilter: the new LayeredCuckooFilter
type LayeredCuckooFilterImpl ¶
type LayeredCuckooFilterImpl struct { *BaseLayeredCacheImpl // contains filtered or unexported fields }
func (*LayeredCuckooFilterImpl) AddLocalFilter ¶
func (lc *LayeredCuckooFilterImpl) AddLocalFilter(key string, filter local.Filter) error
func (*LayeredCuckooFilterImpl) LoadDump ¶
func (lb *LayeredCuckooFilterImpl) LoadDump(ctx context.Context) error
func (*LayeredCuckooFilterImpl) OnMessage ¶
func (lb *LayeredCuckooFilterImpl) OnMessage(ctx context.Context, from string, message interface{}) error
func (*LayeredCuckooFilterImpl) UnWatch ¶
func (lc *LayeredCuckooFilterImpl) UnWatch() error
type LayeredCuckooFilterOptions ¶
type LayeredCuckooFilterOptions struct { RDB *redis.Client Watcher *source.WatchOptions Log *logrus.Logger Entries uint64 Errors float64 Channel interface{} KeyPrefix string Strategy CacheReadStrategy DefaultBuildCuckooOptions *gocuckoo.CuckooBuildOptions }
LayeredBloomFilterOptions is the options for building the layered bloom filter
type LayeredFilter ¶
type LayeredFilter interface { Watcher Loader Check(ctx context.Context, key string, value []byte) (bool, error) Add(ctx context.Context, key string, value []byte) error AddLocalFilter(key string, filter local.Filter) error }
func NewLayeredBloom ¶
func NewLayeredBloom(options *LayeredBuildOptions, bloomOptions gobloom.BloomBuildOptions, extOptions ...LayeredFilterOptions) LayeredFilter
NewLayeredBloom creates a new LayeredBloomFilter. It is only for bloom filter. The bloom filter is a layered cache, which means it has a local bloom filter cache and a redis bloom filter cache.
Parameters:
- options: LayeredBuildOptions is a struct that contains the options for building the layered cache.
- bloomOptions: gobloom.BloomBuildOptions is the configuration for the local bloom filter.
Returns:
- LayeredBloomFilter: the new LayeredBloomFilter
type LayeredFilterOptions ¶
type LayeredFilterOptions func(layered LayeredFilter) error
func WithInitLocalFilterOptions ¶
func WithInitLocalFilterOptions(filters map[string]local.Filter) LayeredFilterOptions
type LayeredKeyValueCache ¶
type LayeredKeyValueCache interface { // LayeredCache LayeredLocalCache Watcher Loader Get(ctx context.Context, key string) ([]byte, error) Set(ctx context.Context, key string, value []byte, exp time.Duration) error Del(ctx context.Context, key string) error }
func NewKeyValueCache ¶
func NewKeyValueCache(ctx context.Context, options LayeredBuildOptions, maxEntries int) (LayeredKeyValueCache, error)
NewKeyValueCache creates a new LayeredKeyValueCache. It is only for key-value cache. The cache is a layered cache, which means it has a local cache and a source cache. The local cache is a bigcache, and the source cache is a redis cache.
Parameters:
- ctx: context.Context
- options: LayeredBuildOptions is a struct that contains the options for building the cache.
- cacheConfig: bigcache.Config is the configuration for the bigcache.
- maxEntries: int is the max entries for the bigcache.
Returns:
- LayeredKeyValueCache: the new LayeredKeyValueCache
- error: if any error occurs
type LayeredKeyValueCacheImpl ¶
type LayeredKeyValueCacheImpl struct { *BaseLayeredCacheImpl // contains filtered or unexported fields }
func (*LayeredKeyValueCacheImpl) Del ¶
func (lc *LayeredKeyValueCacheImpl) Del(ctx context.Context, key string) error
func (*LayeredKeyValueCacheImpl) LoadDump ¶
func (lb *LayeredKeyValueCacheImpl) LoadDump(ctx context.Context) error
func (*LayeredKeyValueCacheImpl) OnMessage ¶
func (lb *LayeredKeyValueCacheImpl) OnMessage(ctx context.Context, from string, message interface{}) error
func (*LayeredKeyValueCacheImpl) UnWatch ¶
func (lc *LayeredKeyValueCacheImpl) UnWatch() error
type LayeredLocalCache ¶
type LayeredLocalCache interface { GetFromLocal(ctx context.Context, key interface{}, args ...interface{}) ([]interface{}, error) SetToLocal(ctx context.Context, key interface{}, args ...interface{}) error }
LayeredLocalCache is the interface for the local cache
type WithDelOperator ¶
type WithLayeredCuckooOptions ¶
type WithLayeredCuckooOptions func(layered LayeredCuckooFilter) error