Go 语言的缓存库 FreeCache

码农软件 · 软件分类 · 缓存系统 · 2019-08-30 07:59:40

软件介绍

FreeCache 是一个 Go 语言的缓存库,无额外的 GC 负荷。数百万对象的垃圾收集延迟仅在数百毫秒。

特性:

  • 可存储数以百万计条目

  • 零垃圾收集负荷

  • 高并发而且线程安全的访问

  • 纯 Go 语言实现

  • 支持对象失效

  • 近乎 LRU 的算法

  • 严格限制内存使用

  • 提供一个测试用的服务器,支持一些基本 Redis 命令

示例代码:

cacheSize := 1024*1024
cache := freecache.NewCache(cacheSize)
key := []byte("abc")
val := []byte("def")
expire := 60 // expire in 60 seconds
cache.Set(key, val, expire)
got, err := cache.Get(key)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(string(got))
}
affected := cache.Del(key)
fmt.Println("deleted key ", affected)
fmt.Println("entry count ", cache.EntryCount())

注意事项:

  • 推荐使用 Go 1.4 版本

  • 内存是预先分配的

  • 如果你分配的内存非常大,那么应该设置 debug.SetGCPercent() 到一个很小的比例来获得正常的 GC 频率

FreeCache 通过减少指针的数量来避免 GC 符合,不管对象有多少,指针最多 512 个。

本文地址:https://codercto.com/soft/d/13476.html

Operating Systems

Operating Systems

Remzi Arpaci-Dusseau、Andrea Arpaci-Dusseau / Arpaci-Dusseau Books / 2012-8-19 / USD 21.00

A book about modern operating systems. Topics are broken down into three major conceptual pieces: Virtualization, Concurrency, and Persistence. Includes all major components of modern systems includin......一起来看看 《Operating Systems》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试