remotecache

package
v0.0.85-test Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: AGPL-3.0 Imports: 19 Imported by: 68

Documentation

Index

Constants

View Source
const (
	ServiceName = "RemoteCache"
)

Variables

View Source
var (
	// ErrCacheItemNotFound is returned if cache does not exist
	ErrCacheItemNotFound = errors.New("cache item not found")

	// ErrInvalidCacheType is returned if the type is invalid
	ErrInvalidCacheType = errors.New("invalid remote cache name")
)

Functions

func Register

func Register(value interface{})

Register records a type, identified by a value for that type, under its internal type name. That name will identify the concrete type of a value sent or received as an interface variable. Only types that will be transferred as implementations of interface values need to be registered. Expecting to be used only during initialization, it panics if the mapping between types and names is not a bijection.

Types

type CacheData

type CacheData struct {
	CacheKey  string
	Data      []byte
	Expires   int64
	CreatedAt int64
}

CacheData is the struct representing the table in the database

type CacheStorage

type CacheStorage interface {
	// Get reads object from Cache
	Get(ctx context.Context, key string) (interface{}, error)

	// Set sets an object into the cache. if `expire` is set to zero it will default to 24h
	Set(ctx context.Context, key string, value interface{}, expire time.Duration) error

	// Delete object from cache
	Delete(ctx context.Context, key string) error
}

CacheStorage allows the caller to set, get and delete items in the cache. Cached items are stored as byte arrays and marshalled using "encoding/gob" so any struct added to the cache needs to be registered with `remotecache.Register` ex `remotecache.Register(CacheableStruct{})“

type RemoteCache

type RemoteCache struct {
	SQLStore *sqlstore.SQLStore
	Cfg      *setting.Cfg
	// contains filtered or unexported fields
}

RemoteCache allows Grafana to cache data outside its own process

func NewFakeStore

func NewFakeStore(t *testing.T) *RemoteCache

NewFakeStore creates store for testing

func ProvideService

func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore) (*RemoteCache, error)

func (*RemoteCache) Delete

func (ds *RemoteCache) Delete(ctx context.Context, key string) error

Delete object from cache

func (*RemoteCache) Get

func (ds *RemoteCache) Get(ctx context.Context, key string) (interface{}, error)

Get reads object from Cache

func (*RemoteCache) Run

func (ds *RemoteCache) Run(ctx context.Context) error

Run starts the backend processes for cache clients.

func (*RemoteCache) Set

func (ds *RemoteCache) Set(ctx context.Context, key string, value interface{}, expire time.Duration) error

Set sets an object into the cache. if `expire` is set to zero it will default to 24h

Jump to

Keyboard shortcuts

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