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>

        BigCache基于 Go 的高效緩存

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

        BigCache 是用于在 Go 中寫入千兆字節(jié)數(shù)據(jù)的高效緩存??焖?,并發(fā),逐行掃描內(nèi)存緩存,以保持大量條目,而不影響性能。 BigCache 在堆上保留條目,但為它們省略了 GC。 要實(shí)現(xiàn)對(duì)字節(jié)數(shù)組的操作,因此在大多數(shù)用例中將需要在高速緩存前面進(jìn)行條目(de)序列化。

        使用

        簡(jiǎn)單初始化

        import "github.com/allegro/bigcache"
        
        cache, _ := bigcache.NewBigCache(bigcache.DefaultConfig(10 * time.Minute))
        
        cache.Set("my-unique-key", []byte("value"))
        
        entry, _ := cache.Get("my-unique-key")
        fmt.Println(string(entry))

        自定義初始化

        import (
        	"log"
        
        	"github.com/allegro/bigcache"
        )
        
        config := bigcache.Config {
        		// number of shards (must be a power of 2)
        		Shards: 1024,
        		// time after which entry can be evicted
        		LifeWindow: 10 * time.Minute,
        		// rps * lifeWindow, used only in initial memory allocation
        		MaxEntriesInWindow: 1000 * 10 * 60,
        		// max entry size in bytes, used only in initial memory allocation
        		MaxEntrySize: 500,
        		// prints information about additional memory allocation
        		Verbose: true,
        		// cache will not allocate more memory than this limit, value in MB
        		// if value is reached then the oldest entries can be overridden for the new ones
        		// 0 value means no size limit
        		HardMaxCacheSize: 8192,
        		// callback fired when the oldest entry is removed because of its
        		// expiration time or no space left for the new entry. Default value is nil which
        		// means no callback and it prevents from unwrapping the oldest entry.
        		OnRemove: nil,
        	}
        
        cache, initErr := bigcache.NewBigCache(config)
        if initErr != nil {
        	log.Fatal(initErr)
        }
        
        cache.Set("my-unique-key", []byte("value"))
        
        if entry, err := cache.Get("my-unique-key"); err == nil {
        	fmt.Println(string(entry))
        }
        瀏覽 28
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        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>
            亚洲有码AV | 就去干成人网 | 日韩午夜精品人妻无码一区二区 | 免费观看黄色毛片 | 天天艹夜夜艹 | 国产一二三四区 | 91一起操 | 一级A片调教打屁股 | 亚洲乱码国产乱码精品精大量 | 亚洲xxxxxxxxx |