当前位置:网站首页>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
边栏推荐
- Required request body is missing problem solving
- How to understand plucker coordinates (geometric understanding)
- Ali two sides: List several tips for Api interface optimization
- schur completement
- Go 结合Gin导出Mysql数据到Excel表格
- Keil编译大小和存储说明
- golang : Zap日志整合
- 上传文件--文件类型大全,图片类型,文档类型,视频类型,压缩包类型
- 让百度地图生成器里的“标注”内容展开--解决方案
- The Geometric Meaning of Vector Cross Product and the Calculation of Modulus
猜你喜欢
随机推荐
Go uses the mencached cache
go : go gin返回JSON数据
Local Implicit Grid Representations for 3D Scenes详解
taro 打包编译报错
@Bean 与 @Component 用在同一个类上,会怎样?
interface
C# 使用RestSharp 实现Get,Post 请求(2)
相机坐标系,世界坐标系,像素坐标系三者转换,以及OPENGLDEFocal Length和Opengl 的 Fov转换
MySQL题外篇【ORM思想解析】
什么是微服务?
DHCP principle and configuration
Electron日常学习笔记
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及
Electron使用romote报错 : Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
Go: go - redis based operation
这个终端连接工具,碾压Xshell
千万级数据量的表,怎样最快速度查询?
redis实现分布式锁的原理
uniapp中canvas与v-if更“配”
理解和熟悉递归中的尝试