go内存缓存BigCache之Entry封装源码阅读
更新时间:2023年09月05日 14:05:39 作者:海生
这篇文章主要介绍了go内存缓存BigCache之Entry封装源码阅读
介绍
在bigcache存储中,数据值存储的形式为[]byte。
我们通过一个,存储的时候,同时会把 hash值,key值,时间戳,entry同时存起来。
我们可以简称为 header + entry
header的存储大小为 18字节 [18]byte
通过wrapEntry()函数封装
const ( timestampSizeInBytes = 8 // Number of bytes used for timestamp hashSizeInBytes = 8 // Number of bytes used for hash keySizeInBytes = 2 // Number of bytes used for size of entry key headersSizeInBytes = timestampSizeInBytes + hashSizeInBytes + keySizeInBytes // Number of bytes used for all headers ) func wrapEntry(timestamp uint64, hash uint64, key string, entry []byte, buffer *[]byte) []byte { keyLength := len(key) blobLength := len(entry) + headersSizeInBytes + keyLength if blobLength > len(*buffer) { *buffer = make([]byte, blobLength) } blob := *buffer binary.LittleEndian.PutUint64(blob, timestamp) binary.LittleEndian.PutUint64(blob[timestampSizeInBytes:], hash) binary.LittleEndian.PutUint16(blob[timestampSizeInBytes+hashSizeInBytes:], uint16(keyLength)) copy(blob[headersSizeInBytes:], key) copy(blob[headersSizeInBytes+keyLength:], entry) return blob[:blobLength] }
以上就是go内存缓存BigCache之Entry封装源码阅读的详细内容,更多关于go内存缓存BigCache Entry的资料请关注脚本之家其它相关文章!
相关文章
golang gin 监听rabbitmq队列无限消费的案例代码
这篇文章主要介绍了golang gin 监听rabbitmq队列无限消费,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-12-12golang 监听服务的信号,实现平滑启动,linux信号说明详解
这篇文章主要介绍了golang 监听服务的信号,实现平滑启动,linux信号说明详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2021-05-05
最新评论