remotecache

package
v0.0.0-testrgm6 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: AGPL-3.0 Imports: 18 Imported by: 83

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")
)
View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

This section is empty.

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 gets the cache value as an byte array
	Get(ctx context.Context, key string) ([]byte, error)

	// Set saves the value as an byte array. if `expire` is set to zero it will default to 24h
	Set(ctx context.Context, key string, value []byte, expire time.Duration) error

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

	// Count returns the number of items in the cache.
	// Optionaly a prefix can be provided to only count items with that prefix
	// DO NOT USE. Not available for memcached.
	Count(ctx context.Context, prefix string) (int64, 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{})`

func NewFakeCacheStorage

func NewFakeCacheStorage() CacheStorage

type FakeCacheStorage

type FakeCacheStorage struct {
	Storage map[string][]byte
}

func (FakeCacheStorage) Count

func (fcs FakeCacheStorage) Count(_ context.Context, prefix string) (int64, error)

func (FakeCacheStorage) Delete

func (fcs FakeCacheStorage) Delete(_ context.Context, key string) error

func (FakeCacheStorage) Get

func (fcs FakeCacheStorage) Get(_ context.Context, key string) ([]byte, error)

func (FakeCacheStorage) Set

func (fcs FakeCacheStorage) Set(_ context.Context, key string, value []byte, exp time.Duration) error

type RemoteCache

type RemoteCache struct {
	SQLStore db.DB
	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 db.DB, usageStats usagestats.Service,
	secretsService secrets.Service) (*RemoteCache, error)

func (*RemoteCache) Count

func (ds *RemoteCache) Count(ctx context.Context, prefix string) (int64, error)

Count returns the number of items in the cache.

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) ([]byte, error)

Get returns the cached value as an byte array

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 []byte, expire time.Duration) error

Set stored the byte array in the cache

Jump to

Keyboard shortcuts

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