Skip to content

huanggangfeng/go-concurrent-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-concurrent-cache

Provide a a high perforamnce, thread safety memory cache, some improvement on the go-cache,

func onEvicted(s string, obj interface{}) {
	....
}

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	cache := cache.New(ctx, cache.Options{
		Expiration:           time.Second * 1,
		CleanupInterval:      time.Second * 10,
		RenewExpirationOnGet: false,
		Evicted:              onEvicted,
	})

	cache.Set("key1", 100)
	cache.SetWithExpiration("key2", 200, time.Second*10)

	o1, err := cache.Get("key1")
	if err != nil {
		fmt.Println(err)
	}

	objects := cache.GetAllObject()
	cache.Clean()
}

About

A high performance and thread safety memory cache

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages