当前位置:网站首页>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
边栏推荐
- Proof of distance calculation from space vertex to plane and its source code
- go : 使用 grom 删除数据库数据
- Ali two sides: Sentinel vs Hystrix comparison, how to choose?
- 首届人工智能安全大赛正式启动
- Oracle查看表空间使用率及爆满解决方案
- STL源码剖析:bound friend template friend代码测试和理解
- uniapp中canvas与v-if更“配”
- schur completement
- Go 结合Gin导出Mysql数据到Excel表格
- 相机坐标系,世界坐标系,像素坐标系三者转换,以及OPENGLDEFocal Length和Opengl 的 Fov转换
猜你喜欢

Redis download and installation

STL源码剖析:迭代器的概念理解,以及代码测试。

RAID disk array

和AI一起玩儿剧本杀:居然比我还入戏

golang : Zap log integration

CTO说不建议我使用SELECT * ,这是为什么?

Ali two sides: List several tips for Api interface optimization

Station B collapsed, what would you do if you were the developer in charge that night?

Go uses the mencached cache

bean的生命周期
随机推荐
千万级数据量的表,怎样最快速度查询?
上传文件--文件类型大全,图片类型,文档类型,视频类型,压缩包类型
开发常用工具软件
从追赶到超越,国产软件大显身手
Develop common tool software
mysql高阶语句(一)
空间平面相交的直线的计算及其源码
Electron之初出茅庐——搭建环境并运行第一个程序
AI can identify race from X-rays, but no one knows why
taro 打包编译报错
华为发布“十大发明”,包含计算、智能驾驶等新领域
goto语句
STL源码剖析:迭代器的概念理解,以及代码测试。
首届人工智能安全大赛正式启动
golang : Zap log integration
五号黯区靶场 mysql 注入之limit注入记录
识别“数据陷阱”,发现数据的可疑之处
Mobile phone side scroll to page to specify location
理解和熟悉递归中的尝试
Go语学习笔记 - gorm使用 - 数据库配置、表新增 Web框架Gin(七)