<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          BigCache基于 Go 的高效緩存

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

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

          使用

          簡單初始化

          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
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产黄片在线播放 | 8050网午夜影院 | 亚洲狼人综合干视频 | 豆花视频在线看成人网站 | 青青草成人无码视频 |