BigCache 使用 基于 Go 的高效缓存

程序名称:BigCache 使用

授权协议: Apache

操作系统: 跨平台

开发语言: Google Go

BigCache 使用 介绍

BigCache 是用于在 Go 中写入千兆字节数据的高效缓存。快速,并发,逐行扫描内存缓存,以保持大量条目,而不影响性能。 BigCache
在堆上保留条目,但为它们省略了 GC。 要实现对字节数组的操作,因此在大多数用例中将需要在高速缓存前面进行条目(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))
}

BigCache 使用 官网

https://allegro.tech/2016/03/writing-fast-cache-service-in-go.html

相关编程语言

BlazeDS 是一个基于服务器的Java 远程控制(remoting...
OVal 是一个可扩展的Java对象数据验证框架,验证的规...
Volta 是一套开发工具,专为开发分布式、实时系统应...
OpenDDS 是一个开源的 C++ 实现的 对象管理组织 OMG...
JADE (Java Agent DEvelopment Framework) 是一个完...
FastMM ,在D2006和2007中已代替了原来的内存管理器。