Help us shape the future of Go! Take the 2026 Go Developer Survey

ttlcache

package module
v0.0.0-...-92b4172 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 2 Imported by: 0

README

This is a ttlcache in the Go.

LICENSE Build Status Go Report Card Godoc

Installation

go get github.com/0x5010/ttlcache

Usage

Get and set with default ttlcache:

// cache bytes
ttlcache.Set("key", []byte("value"), time.Duration(30*time.Second))

// get
b, ok := ttlcache.Get("key")
// cache other with gob
type Test struct {
	V  [][]string
}

var test Test
...
var serialize bytes.Buffer
encoder := gob.NewEncoder(&serialize)
err := encoder.Encode(testStruct)
if err != nil {
	return nil, err
}
ttlcache.Set("key", serialize.Bytes(), time.Duration(30*time.Second))

// get
b, ok := ttlcache.Get("key")

t := &Test{}
decoder := gob.NewDecoder(bytes.NewReader(b))
err := decoder.Decode(t)

new cache:

myCache := ttlcache.New(time.Duration(20 * time.Minute))

myCache.Set("key", []byte("value"), time.Duration(30*time.Second))

b, ok := myCache.Get("key")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count() int

Count 当前缓存个数

func Get

func Get(key string) ([]byte, bool)

Get 从默认缓存中读取

func Set

func Set(key string, value []byte, ttl time.Duration)

Set 设置缓存到默认缓存中

Types

type CoverageCache

type CoverageCache struct {
	// contains filtered or unexported fields
}

CoverageCache 缓存

func New

func New(duration time.Duration) *CoverageCache

New 新建缓存

func (*CoverageCache) Count

func (cache *CoverageCache) Count() int

Count 获取缓存个数

func (*CoverageCache) Get

func (cache *CoverageCache) Get(key string) (data []byte, found bool)

Get 获取缓存

func (*CoverageCache) Set

func (cache *CoverageCache) Set(key string, data []byte, ttl time.Duration)

Set 缓存数据

Jump to

Keyboard shortcuts

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