BigCache 基于 Go 的高效缓存开源项目

我要开发同款
匿名用户2017年10月06日
150阅读

技术信息

开源地址
https://github.com/allegro/bigcache
授权协议
Apache

作品详情

BigCache是用于在Go中写入千兆字节数据的高效缓存。快速,并发,逐行扫描内存缓存,以保持大量条目,而不影响性能。BigCache在堆上保留条目,但为它们省略了GC。要实现对字节数组的操作,因此在大多数用例中将需要在高速缓存前面进行条目(de)序列化。

使用

简单初始化

import "github.com/allegro/bigcache"cache, _ := bigcache.NewBigCache(bigcache.DefaultCofig(10 * time.Miute))cache.Set("my-uique-key", []byte("value"))etry, _ := cache.Get("my-uique-key")fmt.Pritl(strig(etry))

自定义初始化

import ("log""github.com/allegro/bigcache")cofig := bigcache.Cofig {// umber of shards (must be a power of 2)Shards: 1024,// time after which etry ca be evictedLifeWidow: 10 * time.Miute,// rps * lifeWidow, used oly i iitial memory allocatioMaxEtriesIWidow: 1000 * 10 * 60,// max etry size i bytes, used oly i iitial memory allocatioMaxEtrySize: 500,// prits iformatio about additioal memory allocatioVerbose: true,// cache will ot allocate more memory tha this limit, value i MB// if value is reached the the oldest etries ca be overridde for the ew oes// 0 value meas o size limitHardMaxCacheSize: 8192,// callback fired whe the oldest etry is removed because of its// expiratio time or o space left for the ew etry. Default value is il which// meas o callback ad it prevets from uwrappig the oldest etry.ORemove: il,}cache, iitErr := bigcache.NewBigCache(cofig)if iitErr != il {log.Fatal(iitErr)}cache.Set("my-uique-key", []byte("value"))if etry, err := cache.Get("my-uique-key"); err == il {fmt.Pritl(strig(etry))}

功能介绍

BigCache 是用于在 Go 中写入千兆字节数据的高效缓存。快速,并发,逐行扫描内存缓存,以保持大量条目,而不影响性能。 BigCache 在堆上保留条目,但为它们省略了 GC。 要实现对字...

示例图片

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论