gocache

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT, MIT Imports: 5 Imported by: 0

README

Gocache 缓存驱动

基于 github.com/patrickmn/go-cache 实现的本地缓存驱动

配置说明

#TOML版本,其他版本可以根据对应格式配置
"Driver"="gocache"
"TTL"="1800"
//默认过期时间,单位为秒,默认值60
"DefaultExpirationInSecond"=1800
//清理过期数据间隔,单位为秒,默认值60
"CleanupIntervalInSecond"=1800

Documentation

Overview

Package gocache provides cache driver uses memory to store cache data. Using github.com/allegro/bigcache as driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	cache.DriverUtil
	// contains filtered or unexported fields
}

Cache The gocache cache Driver.

func (*Cache) Close

func (c *Cache) Close() error

Close Close cache. Return any error if raised

func (*Cache) Del

func (c *Cache) Del(key string) error

Del Delete data in cache by given key. Return any error raised.

func (*Cache) DelCounter

func (c *Cache) DelCounter(key string) error

DelCounter Delete int val in cache by given key.Count cache and data cache are in two independent namespace. Return any error raisegrd.

func (*Cache) Expire

func (c *Cache) Expire(key string, ttl time.Duration) error

Expire set cache value expire duration by given key and ttl

func (*Cache) ExpireCounter

func (c *Cache) ExpireCounter(key string, ttl time.Duration) error

ExpireCounter set cache counter expire duration by given key and ttl

func (*Cache) Flush

func (c *Cache) Flush() error

Flush Delete all data in cache. Return any error if raised

func (*Cache) GetBytesValue

func (c *Cache) GetBytesValue(key string) ([]byte, error)

GetBytesValue Get bytes data from cache by given key. Return data bytes and any error raised.

func (*Cache) GetCounter

func (c *Cache) GetCounter(key string) (int64, error)

GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.

func (*Cache) IncrCounter

func (c *Cache) IncrCounter(key string, increment int64, ttl time.Duration) (int64, error)

IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace. Return int data value and any error raised.

func (*Cache) MGetBytesValue

func (c *Cache) MGetBytesValue(keys ...string) (map[string][]byte, error)

MGetBytesValue get multiple bytes data from cache by given keys. Return data bytes map and any error if raised.

func (*Cache) MSetBytesValue

func (c *Cache) MSetBytesValue(data map[string][]byte, ttl time.Duration) error

MSetBytesValue set multiple bytes data to cache with given key-value map. Return any error if raised.

func (*Cache) SetBytesValue

func (c *Cache) SetBytesValue(key string, bytes []byte, ttl time.Duration) error

SetBytesValue Set bytes data to cache by given key. Return any error raised.

func (*Cache) SetCounter

func (c *Cache) SetCounter(key string, v int64, ttl time.Duration) error

SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace. Return any error raised.

func (*Cache) SetGCErrHandler

func (c *Cache) SetGCErrHandler(f func(err error))

SetGCErrHandler Set callback to handler error raised when gc.

func (*Cache) UpdateBytesValue

func (c *Cache) UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error

UpdateBytesValue Update bytes data to cache by given key only if the cache exist. Return any error raised.

type Config

type Config struct {
	DefaultExpirationInSecond int64 //Cache memory usage limie.
	CleanupIntervalInSecond   int64
}

Config Cache driver config.

func (*Config) Create

func (config *Config) Create() (cache.Driver, error)

Create new cache driver. Return cache driver created and any error if raised.

Jump to

Keyboard shortcuts

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