zoukankan      html  css  js  c++  java
  • bigcache,缓存数据

    get 网址,https://github.com/allegro/bigcache

    简单初始化
    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, // Interval between removing expired entries (clean up). // If set to <= 0 then no action is performed. // Setting to < 1 second is counterproductive — bigcache has a one second resolution. CleanWindow: 5 * 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, or because delete was called. A bitmask representing the reason will be returned. // Default value is nil which means no callback and it prevents from unwrapping the oldest entry. OnRemove: nil, // OnRemoveWithReason is a callback fired when the oldest entry is removed because of its expiration time or no space left // for the new entry, or because delete was called. A constant representing the reason will be passed through. // Default value is nil which means no callback and it prevents from unwrapping the oldest entry. // Ignored if OnRemove is specified. OnRemoveWithReason: 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)) }
  • 相关阅读:
    SpringBoot Shiro 配置自定义密码加密器
    SpringBoot Druid 配置详解
    UOJ #164. 【清华集训2015】V | 线段树
    BZOJ 4552 [Tjoi2016&Heoi2016]排序 | 二分答案 线段树
    51nod 1462 树据结构 | 树链剖分 矩阵乘法
    BZOJ 3503 [CQOI2014]和谐矩阵
    BZOJ 4004 [JLOI2015]装备购买 | 线性基
    BZOJ 4785 [Zjoi2017]树状数组 | 二维线段树
    LOJ #2145. 「SHOI2017」分手是祝愿
    LOJ #2141. 「SHOI2017」期末考试
  • 原文地址:https://www.cnblogs.com/yangxinpython/p/13595672.html
Copyright © 2011-2022 走看看