当前位置:网站首页>Go uses freecache for caching
Go uses freecache for caching
2022-07-30 08:03:00 【pedestrians have】
1. Introduction to freecache (hereinafter referred to as free)
A caching library for Go, with zero GC overhead and high concurrency performance, is it awesome?
2, free get
git official website: https://github.com/coocood/freecache
golang get: go get -u github.com/coocood/freecache
I personally think it is a better document: (I have to say that the big guy is well written)
https://juejin.cn/post/7072121084136882183
https://cdmana.com/2022/03/202203071328243883.html
3, golang integration free
go-cashe
├─ .vscode
│ └─ launch.json
├─ freecache
│ └─ free.go
├─ main.go
├─README-free.md
3.1, main code (free.go)
import ("github.com/coocool/freecache")//Initialize Cache// freecache.NewCacheCustomTimer(100*1024*1024, freecache.NewCachedTimer()) This method also worksvar cache = freecache.NewCache(100 * 1024 * 1024)//Set a model structtype FreeCasheModel struct {Key[]byteValue[]byteExpireSeconds int //Expire time-s}//Getfunc FreeGet(free FreeCasheModel) (string, bool) {value, err := cache.Get(free.Key)if err != nil {return "", false}return string(value), true}//GetOrSet// if not, store the new keyfunc FreeCacheGetOrSet(free FreeCasheModel) (string, bool) {retValue, err := cache.GetOrSet(free.Key, free.Value, free.ExpireSeconds)if err != nil {return "", false}return string(retValue), true}//Setfunc FreeCacheSet(free FreeCasheModel) bool {err := cache.Set(free.Key, free.Value, free.ExpireSeconds)if err != nil {return false}return true}//SetAndGetfunc FreeCacheSetAndGet(free FreeCasheModel) (string, bool) {retValue, found, err := cache.SetAndGet(free.Key, free.Value, free.ExpireSeconds)if err != nil {return "", false}return string(retValue), found}//Update the expiration time of the key -- if the key does not exist, an error will be returnedfunc FreeChasheTouch(free FreeCasheModel) bool {err := cache.Touch(free.Key, free.ExpireSeconds)if err != nil {return false}return true}//delete---func FreeCasheDel(free FreeCasheModel) bool {return cache.Del(free.Key)}4. Simple test

5. Supplementary Instructions
1. The code looks very simple, but you need to look at the source code and see how the documentation is implemented.
2. If you want to test the performance problem, teachers can test it yourself, here is just a simple implementation
3、 In the previous document, I wrote the cache of memcached. I think this is simpler, but the application scenarios are different. Memcached is mainly a distributed loop, and multiple projects can be accessed at the same time. Free is more suitable for a single project with high concurrent access.a lot.
6, document code address
https://gitee.com/hjx_RuGuoYunZhiDao/strom-huang-go.git —go-casheCatalog
边栏推荐
猜你喜欢

Boot process and service control

UDP和TCP使用同一个端口,可行吗?

人工肌肉智能材料新突破

The terminal connection tools, rolling Xshell

什么是微服务?

export , export default, import complete usage

Graphical relational database design ideas, this is too vivid

The Society of Mind - Marvin Minsky

Electron之初出茅庐——搭建环境并运行第一个程序

相机坐标系,世界坐标系,像素坐标系三者转换,以及OPENGLDEFocal Length和Opengl 的 Fov转换
随机推荐
The Geometric Meaning of Vector Cross Product and the Calculation of Modulus
限塑令下的新材料——聚乳酸(PLA)
The CTO said I was not advised to use SELECT *, why is that?
Vue2进阶篇-编程式路由导航、缓存路由组件、路由的激活与失活
Playing script killing with AI: actually more involved than me
go : 使用gorm查询记录
MySQL题外篇【ORM思想解析】
深度学习:线性回归模型
assert
开发常用工具软件
从 Google 离职,前Go 语言负责人跳槽小公司
阿里二面:Redis有几种集群方案?我答了4种
Huawei released "ten inventions", including computing, intelligent driving and other new fields
STL source code analysis: conceptual understanding of iterators, and code testing.
AI元学习引入神经科学,医疗效果有望精准提升
Proof of distance calculation from space vertex to plane and its source code
“AI教练”请进家,家庭智能健身蓬勃发展
redis实现分布式锁的原理
Go语学习笔记 - gorm使用 - 数据库配置、表新增 Web框架Gin(七)
和AI一起玩儿剧本杀:居然比我还入戏