cache

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MPL-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	RedisClient // interface for accessing underlying redis client
}

Cache is a wrapper for cache accesses.

func NewCache

func NewCache(r RedisClient) *Cache

NewCache creates a Cache wrapper with underlying redis client assigned.

func (*Cache) GetTypeMtimeKey added in v0.1.20

func (c *Cache) GetTypeMtimeKey(clientID string, dataType int) string

GetTypeMtimeKey returns derived cache key clientID#dataType

func (*Cache) IsTypeMtimeUpdated

func (c *Cache) IsTypeMtimeUpdated(ctx context.Context, clientID string, dataType int, token int64) bool

IsTypeMtimeUpdated check the cache to determine if there might be updates for a specific type for a client. It gets the last seen mtime for clientID#dataType in the cache, return false if it is found and the value is older or equal to client's token, which means the client is already up-to-date. In any other cases, it will return false.

func (*Cache) SetTypeMtime

func (c *Cache) SetTypeMtime(ctx context.Context, clientID string, dataType int, mtime int64)

SetTypeMtime add an entry into cache where key is clientID#dataType, value is the lastest mtime seen on this type for the client.

type RedisClient

type RedisClient interface {
	Set(ctx context.Context, key string, val string, ttl time.Duration) error
	Get(ctx context.Context, key string) (string, error)
	Del(ctx context.Context, keys ...string) error
	FlushAll(ctx context.Context) error
}

RedisClient is a wrapper to support clients for standalone redis and redis cluster.

func NewRedisClient

func NewRedisClient() RedisClient

NewRedisClient create a client for standalone redis or redis cluster.

type RedisClientWithPrometheus

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

RedisClientWithPrometheus implements RedisClient interface with all methods wrapped with Prometheus metrics

func NewRedisClientWithPrometheus

func NewRedisClientWithPrometheus(base RedisClient, instanceName string) RedisClientWithPrometheus

NewRedisClientWithPrometheus returns an instance of the RedisClient decorated with prometheus summary metric

func (RedisClientWithPrometheus) Del added in v0.1.20

func (_d RedisClientWithPrometheus) Del(ctx context.Context, keys ...string) (err error)

Del implements RedisClient

func (RedisClientWithPrometheus) FlushAll

func (_d RedisClientWithPrometheus) FlushAll(ctx context.Context) (err error)

FlushAll implements RedisClient

func (RedisClientWithPrometheus) Get

func (_d RedisClientWithPrometheus) Get(ctx context.Context, key string) (s1 string, err error)

Get implements RedisClient

func (RedisClientWithPrometheus) Set

func (_d RedisClientWithPrometheus) Set(ctx context.Context, key string, val string, ttl time.Duration) (err error)

Set implements RedisClient

Jump to

Keyboard shortcuts

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