cache_proxy

package module
v0.0.0-...-ba9fcfb Latest Latest
Warning

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

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

README

cache-agent

implement a simple cache proxy and analyze several ways of writing Golang programs using concurrency scenarios.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = 10 * time.Second

Functions

This section is empty.

Types

type BaseCacheProxy

type BaseCacheProxy[TCache, TQry any] struct {
	Transform TransformQryOptionToCacheKey
	Cache     Cache[TCache]
	GetDB     DatabaseGetFunc[TCache, TQry]
	KeepTime  time.Duration
}

func (*BaseCacheProxy[TCache, TQry]) Execute

func (proxy *BaseCacheProxy[TCache, TQry]) Execute(ctx context.Context, qryOption TQry, respModel TCache) (TCache, error)

type Cache

type Cache[TCache any] interface {
	GetValue(ctx context.Context, key string, value TCache) (err error)
	SetValue(ctx context.Context, key string, val TCache, keepTime time.Duration) error
}

Cache infrastructure interface

type CacheProxy

type CacheProxy[TCache, TQry any] interface {
	Execute(ctx context.Context, qryOption TQry, readModelType *TCache) (readModel TCache, err error)
}

CacheProxy Proxy interface

func UseMutex

func UseMutex[TCache, TQry any](baseProxy *BaseCacheProxy[TCache, TQry]) CacheProxy[TCache, TQry]

func UseSyncCond

func UseSyncCond[TCache, TQry any](baseProxy *BaseCacheProxy[TCache, TQry]) CacheProxy[TCache, TQry]

func UseSyncMap

func UseSyncMap[TCache, TQry any](baseProxy *BaseCacheProxy[TCache, TQry]) CacheProxy[TCache, TQry]

type DatabaseGetFunc

type DatabaseGetFunc[TCache, TQry any] func(ctx context.Context, qryOption TQry) (readModel TCache, err error)

type MutexProxy

type MutexProxy[TCache, TQry any] struct {
	BaseCacheProxy[TCache, TQry]
	// contains filtered or unexported fields
}

func (*MutexProxy[TCache, TQry]) Execute

func (proxy *MutexProxy[TCache, TQry]) Execute(ctx context.Context, qryOption TQry, readModelType *TCache) (readModel TCache, err error)

type Option

type Option func(*Options)

func KeepTime

func KeepTime(t int64) Option

func KeepTimeRange

func KeepTimeRange(t1, t2 int64) Option

type Options

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

Options setting

func (*Options) GetKeepTime

func (o *Options) GetKeepTime() time.Duration

type RedisCache

type RedisCache[TCache any] struct {
	// contains filtered or unexported fields
}

func NewRedisCache

func NewRedisCache[TCache any](client *redis.Client) *RedisCache[TCache]

func (*RedisCache[TCache]) GetValue

func (m *RedisCache[TCache]) GetValue(ctx context.Context, key string, value TCache) error

func (*RedisCache[TCache]) SetValue

func (m *RedisCache[TCache]) SetValue(ctx context.Context, key string, value TCache, keepTime time.Duration) error

type SyncCondProxy

type SyncCondProxy[TCache, TQry any] struct {
	BaseCacheProxy[TCache, TQry]
	// contains filtered or unexported fields
}

func (*SyncCondProxy[TCache, TQry]) AwaitIdle

func (proxy *SyncCondProxy[TCache, TQry]) AwaitIdle(ctx context.Context, qryOption TQry, readModelType *TCache) (readModel TCache, err error)

func (*SyncCondProxy[TCache, TQry]) Execute

func (proxy *SyncCondProxy[TCache, TQry]) Execute(ctx context.Context, qryOption TQry, readModelType *TCache) (readModel TCache, err error)

func (*SyncCondProxy[TCache, TQry]) SetBusy

func (proxy *SyncCondProxy[TCache, TQry]) SetBusy(b bool)

type SyncMapProxy

type SyncMapProxy[TCache, TQry any] struct {
	BaseCacheProxy[TCache, TQry]
	// contains filtered or unexported fields
}

func (*SyncMapProxy[TCache, TQry]) Execute

func (proxy *SyncMapProxy[TCache, TQry]) Execute(ctx context.Context, qryOption TQry, readModelType *TCache) (readModel TCache, err error)

type TransformQryOptionToCacheKey

type TransformQryOptionToCacheKey func(qryOption any) (key string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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