config

package
v0.1.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	// Domain namespace
	Domain string
	// CacheLevel there are 2 types of cache and 4 kinds of cache option
	CacheLevel CacheLevel

	// CacheStorage choose proper storage medium
	CacheStorage DataLayerInterface

	// Tables only cache data within given data tables (cache all if empty)
	Tables []string

	// InvalidateWhenUpdate
	// if user update/delete/create something in DB, we invalidate all cached data to ensure consistency,
	// else we do nothing to outdated cache.
	InvalidateWhenUpdate bool

	// CacheTTL cache ttl in ms, where 0 represents forever
	CacheTTL int64

	// CacheMaxItemCnt for given query, if objects retrieved are more than this cnt,
	// then we choose not to cache for this query. 0 represents caching all queries.
	CacheMaxItemCnt int64

	// CacheSize maximal items in primary cache (only works in MEMORY storage)
	CacheSize int

	// DebugMode indicate if we're in debug mode (will print access log)
	DebugMode bool

	// DebugLogger
	DebugLogger LoggerInterface
}

type CacheLevel

type CacheLevel int
const (
	CacheLevelOff         CacheLevel = 0
	CacheLevelOnlyPrimary CacheLevel = 1
	CacheLevelOnlySearch  CacheLevel = 2
	CacheLevelAll         CacheLevel = 3
)

type DataLayerInterface

type DataLayerInterface interface {
	Init(config *CacheConfig, prefix string) error

	// read
	BatchKeyExist(ctx context.Context, keys []string) (bool, error)
	KeyExists(ctx context.Context, key string) (bool, error)
	GetValue(ctx context.Context, key string) (string, error)
	BatchGetValues(ctx context.Context, keys []string) ([]string, error)

	// write
	CleanCache(ctx context.Context) error
	DeleteKeysWithPrefix(ctx context.Context, keyPrefix string) error
	DeleteKey(ctx context.Context, key string) error
	BatchDeleteKeys(ctx context.Context, keys []string) error
	BatchSetKeys(ctx context.Context, kvs []util.Kv) error
	SetKey(ctx context.Context, kv util.Kv) error
}

type DefaultLoggerImpl

type DefaultLoggerImpl struct {
	// contains filtered or unexported fields
}

func (*DefaultLoggerImpl) CtxError

func (l *DefaultLoggerImpl) CtxError(ctx context.Context, format string, v ...interface{})

func (*DefaultLoggerImpl) CtxInfo

func (l *DefaultLoggerImpl) CtxInfo(ctx context.Context, format string, v ...interface{})

func (*DefaultLoggerImpl) SetIsDebug

func (l *DefaultLoggerImpl) SetIsDebug(d bool)

type LoggerInterface

type LoggerInterface interface {
	SetIsDebug(debug bool)
	CtxInfo(ctx context.Context, format string, v ...interface{})
	CtxError(ctx context.Context, format string, v ...interface{})
}

type MemoryLayer

type MemoryLayer struct {
	// contains filtered or unexported fields
}

func (*MemoryLayer) BatchDeleteKeys

func (m *MemoryLayer) BatchDeleteKeys(ctx context.Context, keys []string) error

func (*MemoryLayer) BatchGetValues

func (m *MemoryLayer) BatchGetValues(ctx context.Context, keys []string) ([]string, error)

func (*MemoryLayer) BatchKeyExist

func (m *MemoryLayer) BatchKeyExist(ctx context.Context, keys []string) (bool, error)

func (*MemoryLayer) BatchSetKeys

func (m *MemoryLayer) BatchSetKeys(ctx context.Context, kvs []util.Kv) error

func (*MemoryLayer) CleanCache

func (m *MemoryLayer) CleanCache(ctx context.Context) error

func (*MemoryLayer) DeleteKey

func (m *MemoryLayer) DeleteKey(ctx context.Context, key string) error

func (*MemoryLayer) DeleteKeysWithPrefix

func (m *MemoryLayer) DeleteKeysWithPrefix(ctx context.Context, keyPrefix string) error

func (*MemoryLayer) GetValue

func (m *MemoryLayer) GetValue(ctx context.Context, key string) (string, error)

func (*MemoryLayer) Init

func (m *MemoryLayer) Init(conf *CacheConfig, prefix string) error

func (*MemoryLayer) KeyExists

func (m *MemoryLayer) KeyExists(ctx context.Context, key string) (bool, error)

func (*MemoryLayer) SetKey

func (m *MemoryLayer) SetKey(ctx context.Context, kv util.Kv) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL