1 Star 1 Fork 0

maemual / go-cache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

go-cache

GoDoc

An in-memory K/V cache and LRU cache library. Just for fun!

This package provide a simple memory key-value cache and LRU cache. It based on the k/v cache implementation in go-cache and LRU cache implementation in groupcache.

Documentation

API Reference

Installation

Install go-cache using the "go get" command:

go get github.com/maemual/go-cache

Example

Key-value cache:

package main

import (
    "fmt"

    "github.com/maemual/go-cache"
)

func main() {
    c := cache.New(0, 0)
    c.Set("1", 1111, 0)
    val, found := c.Get("1")
    if found {
        fmt.Println(val)
    }
    c.Increment("1", 1)
    val, found = c.Get("1")
    if found {
        fmt.Println(val)
    }
}

LRU Cache:

package main

import (
    "fmt"

    "github.com/maemual/go-cache"
)

func main() {
    lru, err := cache.NewLRU(3)
    if err != nil {
        fmt.Println(err)
    }
    lru.Add("1", 1111)
    lru.Add("2", 2222)
    lru.Add("3", 3333)
    lru.Add("4", 4444)
    _, hit := lru.Get("1")
    if hit {
        fmt.Println("Hit key 1")
    } else {
        fmt.Println("Not hit key 1")
    }

}

空文件

简介

An in-memory K/V cache library. Just for fun! 展开 收起
Go
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/maemual/go-cache.git
git@gitee.com:maemual/go-cache.git
maemual
go-cache
go-cache
master

搜索帮助