cache

package
v0.0.0-...-e779149 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeInMemoryCache = "InMemoryCache"
)

Variables

View Source
var ErrNoSuchKey = errors.New("no such key")
View Source
var NeverExpire = time.Duration(0)

Functions

func RegisterCacheFactory

func RegisterCacheFactory(factory CacheFactory)

Types

type CacheFactory

type CacheFactory interface {
	// Type unique type of the cache
	Type() string
	// Create relevant caches by type
	Create(options options.DynamicOptions, stopCh <-chan struct{}) (Interface, error)
}

type InMemoryCacheOptions

type InMemoryCacheOptions struct {
	CleanupPeriod time.Duration `json:"cleanupPeriod" yaml:"cleanupPeriod" mapstructure:"cleanupperiod"`
}

InMemoryCacheOptions used to create inMemoryCache in memory. CleanupPeriod specifies cleans up expired token every period. Note the SimpleCache cannot be used in multi-replicas apiserver, which will lead to data inconsistency.

type Interface

type Interface interface {
	// Keys retrieves all keys match the given pattern
	Keys(pattern string) ([]string, error)

	// Get retrieves the value of the given key, return error if key doesn't exist
	Get(key string) (string, error)

	// Set sets the value and living duration of the given key, zero duration means never expire
	Set(key string, value string, duration time.Duration) error

	// Del deletes the given key, no error returned if the key doesn't exist
	Del(keys ...string) error

	// Exists checks the existence of a give key
	Exists(keys ...string) (bool, error)

	// Expire updates object's expiration time, return err if key doesn't exist
	Expire(key string, duration time.Duration) error
}

func New

func New(option *Options, stopCh <-chan struct{}) (Interface, error)

func NewInMemoryCache

func NewInMemoryCache(options *InMemoryCacheOptions, stopCh <-chan struct{}) (Interface, error)

func NewRedisClient

func NewRedisClient(option *redisOptions, stopCh <-chan struct{}) (Interface, error)

type Options

type Options struct {
	Type    string                 `json:"type"`
	Options options.DynamicOptions `json:"options"`
}

func NewCacheOptions

func NewCacheOptions() *Options

NewCacheOptions returns options points to nowhere, because redis is not required for some components

func (*Options) Validate

func (r *Options) Validate() []error

Validate check options

Jump to

Keyboard shortcuts

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