camCache

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheComponent

type CacheComponent struct {
	component.Component
	camBase.CacheComponentInterface
	// contains filtered or unexported fields
}

cache component

func (*CacheComponent) Del

func (comp *CacheComponent) Del(keys ...string) error

delete cache

func (*CacheComponent) Exists

func (comp *CacheComponent) Exists(key string) bool

whether the key exists

func (*CacheComponent) Flush

func (comp *CacheComponent) Flush() error

delete all cache

func (*CacheComponent) Get

func (comp *CacheComponent) Get(key string) interface{}

get value by key

func (*CacheComponent) Init

func (comp *CacheComponent) Init(configI camBase.ComponentConfigInterface)

init config

func (*CacheComponent) Set

func (comp *CacheComponent) Set(key string, value interface{}) error

set cache

func (*CacheComponent) SetDuration

func (comp *CacheComponent) SetDuration(key string, value interface{}, duration time.Duration) error

set cache with duration

func (*CacheComponent) Start

func (comp *CacheComponent) Start()

start

func (*CacheComponent) Stop

func (comp *CacheComponent) Stop()

stop

type CacheComponentConfig

type CacheComponentConfig struct {
	component.ComponentConfig

	Engine          CacheInterface
	DefaultDuration time.Duration
}

cache component config

func NewCacheConfig

func NewCacheConfig() *CacheComponentConfig

new cache config

type CacheInterface

type CacheInterface interface {
	// init cache driver. connect server or create cache system
	Init() error
	// put cache
	Set(key string, value interface{}, duration time.Duration) error
	// get cache
	Get(key string) interface{}
	// delete cache
	Del(keys ...string) error
	// get GC interval
	GetGCInterval() time.Duration
	// garbage collection
	GC() error
	// clear all cache
	Flush() error
}

cache driver interface

type FileCache

type FileCache struct {
	CacheInterface

	DirDepth   int           // cache dir depth
	FilePath   string        // cache dir
	GcCheckNum int           // number of times to check file whether GC
	GCInterval time.Duration // GC interval
}

func NewFileCache

func NewFileCache() *FileCache

func (*FileCache) Del

func (cache *FileCache) Del(keys ...string) error

delete value form engine

func (*FileCache) Flush

func (cache *FileCache) Flush() error

clear all cache

func (*FileCache) GC

func (cache *FileCache) GC() error

garbage collection

func (*FileCache) Get

func (cache *FileCache) Get(key string) interface{}

get value

func (*FileCache) GetGCInterval

func (cache *FileCache) GetGCInterval() time.Duration

get GC interval

func (*FileCache) Init

func (cache *FileCache) Init() error

init engine

func (*FileCache) Set

func (cache *FileCache) Set(key string, value interface{}, duration time.Duration) error

put key-value to engine

type FileCacheAo

type FileCacheAo struct {
	Value         interface{} `json:"v"`
	DeadTimestamp float64     `json:"dt"` // timestamp in seconds
}

file cache application object

func NewFileCacheAo

func NewFileCacheAo(value interface{}, duration time.Duration) *FileCacheAo

new object

func (*FileCacheAo) IsDead

func (ao *FileCacheAo) IsDead() bool

is dead

func (*FileCacheAo) IsDeadNano

func (ao *FileCacheAo) IsDeadNano() bool

is dead. Accurate to nanosecond

type RedisCache

type RedisCache struct {
	CacheInterface
	Addr     string
	Password string
	DB       int
	// contains filtered or unexported fields
}

redis cache engine

func NewRedisEngine

func NewRedisEngine() *RedisCache

new redis engine

func (*RedisCache) Del

func (cache *RedisCache) Del(keys ...string) error

delete value form engine

func (*RedisCache) Flush

func (cache *RedisCache) Flush() error

clear all cache

func (*RedisCache) GC

func (cache *RedisCache) GC() error

garbage collection

func (*RedisCache) Get

func (cache *RedisCache) Get(key string) interface{}

get value

func (*RedisCache) GetGCInterval

func (cache *RedisCache) GetGCInterval() time.Duration

get GC interval

func (*RedisCache) Init

func (cache *RedisCache) Init() error

init engine

func (*RedisCache) Set

func (cache *RedisCache) Set(key string, value interface{}, duration time.Duration) error

put key-value to engine

Jump to

Keyboard shortcuts

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