The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
PungentSauce

go 如果引入第三方内存缓存库的话,引入哪个好?

  •  
  •   PungentSauce · Jul 17, 2025 · 5909 views
    This topic created in 480 days ago, the information mentioned may be changed or developed.

    go 如果引入第三方内存缓存库的话,引入哪个好? 之前有用过,后来觉得有些使用场景比较小就改成 sync.map 了 ,现在用的场景有点多了。想要引入个质量高一点的第三方内存缓存库

    Supplement 1  ·  Jul 17, 2025
    我这边希望缓存的是 value ,有的是查询缓存,不想缓存 string/[]byte , 目前 otto 感觉比 bigcache 慢,但是 bigcache 只能[]byte ,还是很纠结。
    40 replies  •  2025-07-22 13:22:46 +08:00
    ripperdev
    ripperdev
    Jul 17, 2025
    3
    https://github.com/hashicorp/go-memdb 最近在用这个,consul 家出的
    cannotagreemore
    cannotagreemore
    Jul 17, 2025
    4
    我司大规模项目在用,自研 sdk 也集成了这个实现,设计和文档质量都还不错
    https://github.com/hypermodeinc/ristretto
    Reficul
    Reficul
    Jul 17, 2025
    5
    具体是啥场景呢?闭眼推一个

    https://github.com/google/btree
    lepig
    lepig
    Jul 17, 2025❤️12
    6
    卧槽
    5 个回复,5 个库。OP 岂不是更加就纠结了
    jenner1331
    jenner1331
    Jul 17, 2025
    7
    anycache
    LinusWong
    LinusWong
    Jul 17, 2025❤️2
    8
    这就是 go 吗,太百花齐放了
    wkzq
    wkzq
    Jul 17, 2025
    10
    https://github.com/coocood/freecache
    目前公司在用这个
    Aug
    Aug
    Jul 17, 2025
    11
    选活跃的
    cooltechbs
    cooltechbs
    Jul 17, 2025
    12
    @LinusWong 碎片化哈哈哈
    me262
    me262
    Jul 17, 2025
    13
    楼上推荐的这些应用场景都不一样,用 ai 对比一下
    billbur
    billbur
    Jul 17, 2025❤️2
    14
    @lepig 笑死我了,这就是 go
    Rehtt
    Rehtt
    Jul 17, 2025
    15
    根据需求自己搓一个
    csfreshman
    csfreshman
    Jul 17, 2025
    16
    百花齐放百家争鸣
    dabaibai
    dabaibai
    Jul 17, 2025
    17
    直接来个性能对比图 让大家选
    beihanggmj
    beihanggmj
    Jul 17, 2025
    18
    @lepig #6 😇😇😇
    ChunkitAu
    ChunkitAu
    Jul 17, 2025
    19
    go-cache +1 使用也简单,当然看你项目规模,规模小 go-cache 足够使用了
    craftsmanship
    craftsmanship
    Jul 17, 2025 via Android
    20
    Mode Python 笑而不语
    PungentSauce
    PungentSauce
    OP
    Jul 17, 2025
    21
    我忘记之前用过 go-cache 还是 big-cache 了。 性能和功能性两方面吧。好多第三方 cache 不支持按照 key 进行过期设置就比较麻烦。
    me221
    me221
    Jul 17, 2025
    22
    让我惊讶的是几个库的更新时间已经是几年前了?

    go-cache: 6 years ago
    btree: 11 months ago

    Go 的兼容性这么好嘛
    chimission
    chimission
    Jul 17, 2025❤️1
    23
    @me221 go1.x 的更新开发者保证都是向后兼容的, 但是不保证以后得 go2
    chimission
    chimission
    Jul 17, 2025
    24
    我以前也是用的 go-cache 简单够用, 唯一不足就是不更新了,不过这个库做内存缓存也够了,更新不更新无所谓
    matrix1010
    matrix1010
    Jul 17, 2025❤️2
    25
    @cannotagreemore 你司要不要考虑换一换?建议看看 https://news.ycombinator.com/item?id=44414630 。作为 Theine 的作者我向你推荐 otter
    wnanbei
    wnanbei
    Jul 17, 2025
    27
    @chimission 已经没有 Go2 咯,只会有 1.xxx
    noyidoit
    noyidoit
    Jul 17, 2025
    28
    go-cache+1 ,简单够用
    looplj
    looplj
    Jul 17, 2025
    29
    @matrix1010 #25 v2 大佬真多,我在用 theine ,还提过 issue 来着
    StarUDream
    StarUDream
    Jul 17, 2025
    30
    https://github.com/eko/gocache

    话说还有没有类似这样的库,上层统一接口,下层可以使用 redis menory 这样的
    wervserwe
    wervserwe
    Jul 17, 2025
    31
    自己根据需求写个
    spiritfelix
    spiritfelix
    Jul 18, 2025
    33
    看需求吧,我甚至用了 SQLite 做本地数据存储,目的是有些数据,关闭应用继续保留,开启应用继续使用,哦,忘了说,Wails 桌面端应用
    qloog
    qloog
    Jul 20, 2025
    34
    https://github.com/hypermodeinc/ristretto 这个就很不错,各方面指标都很不错

    ristretto 详细对比: https://hypermode.com/blog/introducing-ristretto-high-perf-go-cache 里面也提到了关于性能提升的一些关键点和参考,也有一些性能对比的参考图

    作为 local cache 使用的案例: https://github.com/go-eagle/eagle/blob/master/pkg/cache/memory.go
    qloog
    qloog
    Jul 20, 2025
    35
    @Ayanokouji 看到 grafana 也在使用 otter
    badbye
    badbye
    Jul 21, 2025
    37
    @ripperdev 想找个 go 对 leveldb/rocksdb 的封装,支持事务的,软件事务内存
    815979670
    815979670
    Jul 21, 2025
    38
    我再补一个 GORM+SQLite 驱动+内存库,我们项目中时这样用的,启动时加载数据,然后可以通过 SQL 语句 汇总、查询过滤。(我们是定时统计数据 维度较多 选了这个方案)
    gongym
    gongym
    Jul 22, 2025
    39
    我记得我之前也做过选型,后来选了 redis
    pmx1990
    pmx1990
    Jul 22, 2025
    40
    @ripperdev +1024 4 年前已经用于生产了 自己用范型 封装下 很好用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2335 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 110ms · UTC 13:11 · PVG 21:11 · LAX 05:11 · JFK 08:11
    ♥ Do have faith in what you're doing.