remotecache

package
v0.0.0-...-34a2968 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

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(key string) (interface{}, error)

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

	// Delete object from cache
	Delete(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 `inject:""`
	Cfg      *setting.Cfg       `inject:""`
	// 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 (*RemoteCache) Delete

func (ds *RemoteCache) Delete(key string) error

Delete object from cache

func (*RemoteCache) Get

func (ds *RemoteCache) Get(key string) (interface{}, error)

Get reads object from Cache

func (*RemoteCache) Init

func (ds *RemoteCache) Init() error

Init initializes the service

func (*RemoteCache) Run

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

Run start the backend processes for cache clients

func (*RemoteCache) Set

func (ds *RemoteCache) Set(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