当前位置:网站首页>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
边栏推荐
- go : create database records using gorm
- RAID disk array
- CTO说不建议我使用SELECT * ,这是为什么?
- Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
- Universal js time date format conversion
- 雷总个人博客看到
- 这个终端连接工具,碾压Xshell
- 云服务器零基础部署网站(保姆级教程)
- Test Development Engineer Growth Diary 015 - Top 20 Test Interview Questions
- AI元学习引入神经科学,医疗效果有望精准提升
猜你喜欢

【MySQL】MySQL中如何实现分页操作

numpy 多维数组ndarray的详解

idea built-in translation plugin

How does Redis prevent oversold and inventory deduction operations?

Let the "label" content in Baidu map generator expand--solution

PXE efficient mass network capacity

分布式系统中的开创者—莱斯利·兰伯特

2020年度总结——品曾经,明得失,展未来
![[硬核干货]由0到1,突破信息系统项目管理师(呕心沥血经验之谈)!!!](/img/9a/f3e4bdd0ce8ec153a8e6bdbff5647e.jpg)
[硬核干货]由0到1,突破信息系统项目管理师(呕心沥血经验之谈)!!!

万能js时间日期格式转换
随机推荐
export , export default,import完整用法
Go uses the mencached cache
sizeof
The newcomer deleted data by mistake, and the team leader skillfully used MySQL master-slave replication to delay the recovery of losses
go : go-redis 基础操作
限塑令下的新材料——聚乳酸(PLA)
Ali two sides: List several tips for Api interface optimization
Local Implicit Grid Representations for 3D Scenes详解
assert
mysql高阶语句(一)
一段神奇的没有主方法的代码
Playing script killing with AI: actually more involved than me
Is it possible to use the same port for UDP and TCP?
golang : Zap log integration
The introduction of AI meta-learning into neuroscience, the medical effect is expected to improve accurately
Table with tens of millions of data, how to query the fastest?
Ali Ermian: How many cluster solutions does Redis have?I answered 4
interface
Upload file -- file type, picture type, document type, video type, compressed package type
go : use gorm to modify data