1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        cache2goGo 緩存庫

        聯(lián)合創(chuàng)作 · 2023-09-29 05:52

        cache2go 是一個 Go 的并發(fā)安全緩存庫,具有到期和訪問計(jì)數(shù)器的功能。

        示例代碼:

        package main
        
        import (
            "github.com/muesli/cache2go"
            "fmt"
            "time"
        )
        
        // Keys & values in cache2go can be off arbitrary types, e.g. a struct.
        type myStruct struct {
            text     string
            moreData []byte
        }
        
        func main() {
            // Accessing a new cache table for the first time will create it.
            cache := cache2go.Cache("myCache")
        
            // We will put a new item in the cache. It will expire after
            // not being accessed via Value(key) for more than 5 seconds.
            val := myStruct{"This is a test!", []byte{}}
            cache.Add("someKey", 5*time.Second, &val)
        
            // Let's retrieve the item from the cache.
            res, err := cache.Value("someKey")
            if err == nil {
                fmt.Println("Found value in cache:", res.Data().(*myStruct).text)
            } else {
                fmt.Println("Error retrieving value from cache:", err)
            }
        
            // Wait for the item to expire in cache.
            time.Sleep(6 * time.Second)
            res, err = cache.Value("someKey")
            if err != nil {
                fmt.Println("Item is not cached (anymore).")
            }
        
            // Add another item that never expires.
            cache.Add("someKey", 0, &val)
        
            // cache2go supports a few handy callbacks and loading mechanisms.
            cache.SetAboutToDeleteItemCallback(func(e *cache2go.CacheItem) {
                fmt.Println("Deleting:", e.Key(), e.Data().(*myStruct).text, e.CreatedOn())
            })
        
            // Remove the item from the cache.
            cache.Delete("someKey")
        
            // And wipe the entire cache table.
            cache.Flush()
        }

         

        go run mycachedapp.go
        瀏覽 43
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            日本裸体大乳mm77图片 | 亚洲国产精品成人久久蜜臀 | 久久一留热品黄 | 免费无码婬片AAAA片上门服务 | 青娱乐欧美精品 | 娇妻玩3p被2个男人伺候了 | 亚洲AV第二区国产精品 | 亚洲黄色免费看 | 尤物视频一区二区 | 国产精品免费观看久久 |