Skip to content

0x5010/ttlcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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")

About

ttlcache in go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages