cache

package
v0.0.0-...-a32ce64 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, adapter Adapter) error

Register adds the cache adapter by name

Types

type Adapter

type Adapter func() Cache

Adapter is the cache instance.

type Cache

type Cache interface {
	// Init initialize the cache adapter with provided config string.
	Init(string) error
	// Get cached value by key.
	Get(string) interface{}
	// GetMulti values of Get.
	GetMulti([]string) []interface{}
	// Put sets the cache value with key and timeout.
	Put(string, interface{}, time.Duration) error
	// Delete cached value by key.
	Delete(string) error
	// Exists check if cached value exists.
	Exists(string) bool
	// ClearAll removes all cached values.
	ClearAll() error
}

Cache contains the base cache adapter.

func NewCache

func NewCache(name, config string) (Cache, error)

NewCache creates the cache instance using the provided adapter and config string (must contain a valid JSON string).

func NewFileCache

func NewFileCache() Cache

NewFileCache instantiate a new FileCache.

func NewMemoryCache

func NewMemoryCache() Cache

NewMemoryCache instantiate a new MemoryCache.

type FileCache

type FileCache struct {
	Path string
	Ext  string
}

FileCache is the file cache adapter.

func (*FileCache) ClearAll

func (fc *FileCache) ClearAll() error

ClearAll removes all cached values.

func (*FileCache) Delete

func (fc *FileCache) Delete(key string) error

Delete cached value by key.

func (*FileCache) Exists

func (fc *FileCache) Exists(key string) bool

Exists check if cached value exists.

func (*FileCache) Get

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

Get cached value by key.

func (*FileCache) GetMulti

func (fc *FileCache) GetMulti(keys []string) []interface{}

GetMulti values of Get.

func (*FileCache) Init

func (fc *FileCache) Init(config string) error

Init initialize the cache adapter with provided config string.

func (*FileCache) Put

func (fc *FileCache) Put(key string, value interface{}, timeout time.Duration) error

Put sets the cache value with key and timeout.

type FileCacheItem

type FileCacheItem struct {
	Content interface{}
	Expire  time.Time
}

FileCacheItem contains the cached data and expire time.

type MemoryCache

type MemoryCache struct {
	sync.RWMutex

	Every int // run an expiration check Every clock time
	// contains filtered or unexported fields
}

MemoryCache is memory cache adapter.

func (*MemoryCache) ClearAll

func (mc *MemoryCache) ClearAll() error

ClearAll removes all cached values.

func (*MemoryCache) Delete

func (mc *MemoryCache) Delete(key string) error

Delete cached value by key.

func (*MemoryCache) Exists

func (mc *MemoryCache) Exists(key string) bool

Exists check if cached value exists.

func (*MemoryCache) Get

func (mc *MemoryCache) Get(key string) interface{}

Get cached value by key.

func (*MemoryCache) GetMulti

func (mc *MemoryCache) GetMulti(keys []string) []interface{}

GetMulti values of Get.

func (*MemoryCache) Init

func (mc *MemoryCache) Init(config string) error

Init initialize the cache adapter with provided config string.

func (*MemoryCache) Put

func (mc *MemoryCache) Put(key string, value interface{}, timeout time.Duration) error

Put sets the cache value with key and timeout.

type MemoryCacheItem

type MemoryCacheItem struct {
	Content interface{}
	Expire  time.Time
}

MemoryCacheItem contains the cached data and expire time.

Jump to

Keyboard shortcuts

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