go內(nèi)存緩存BigCache之Entry封裝源碼閱讀
介紹
在bigcache存儲(chǔ)中,數(shù)據(jù)值存儲(chǔ)的形式為[]byte。
我們通過一個(gè),存儲(chǔ)的時(shí)候,同時(shí)會(huì)把 hash值,key值,時(shí)間戳,entry同時(shí)存起來。
我們可以簡(jiǎn)稱為 header + entry
header的存儲(chǔ)大小為 18字節(jié) [18]byte
通過wrapEntry()函數(shù)封裝
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內(nèi)存緩存BigCache之Entry封裝源碼閱讀的詳細(xì)內(nèi)容,更多關(guān)于go內(nèi)存緩存BigCache Entry的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Go-客戶信息關(guān)系系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了Go-客戶信息關(guān)系系統(tǒng)的實(shí)現(xiàn),本文章內(nèi)容詳細(xì),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,需要的朋友可以參考下2023-01-01
golang定時(shí)任務(wù)cron項(xiàng)目實(shí)操指南
Go實(shí)現(xiàn)的cron 表達(dá)式的基本語法跟linux 中的 crontab基本是類似的,下面這篇文章主要給大家介紹了關(guān)于golang定時(shí)任務(wù)cron項(xiàng)目實(shí)操的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
VScode下配置Go語言開發(fā)環(huán)境(2023最新)
在VSCode中配置Golang開發(fā)環(huán)境是非常簡(jiǎn)單的,本文主要記錄了Go的安裝,以及給vscode配置Go的環(huán)境,具有一定的參考價(jià)值,感興趣的可以了解一下2023-10-10

