MyGit
🚩收到GitHub仓库的更新通知

hashicorp/golang-lru

Fork: 480 Star: 4077 (更新于 2024-04-22 15:21:51)

license: MPL-2.0

Language: Go .

Golang LRU cache

最后发布版本: v2.0.7 ( 2023-09-30 00:49:56)

GitHub网址

✨免费申请网站SSL证书,支持多域名和泛域名,点击查看

golang-lru

This provides the lru package which implements a fixed-size thread safe LRU cache. It is based on the cache in Groupcache.

Documentation

Full docs are available on Go Packages

LRU cache example

package main

import (
	"fmt"
	"github.com/hashicorp/golang-lru/v2"
)

func main() {
	l, _ := lru.New[int, any](128)
	for i := 0; i < 256; i++ {
		l.Add(i, nil)
	}
	if l.Len() != 128 {
		panic(fmt.Sprintf("bad len: %v", l.Len()))
	}
}

Expirable LRU cache example

package main

import (
	"fmt"
	"time"

	"github.com/hashicorp/golang-lru/v2/expirable"
)

func main() {
	// make cache with 10ms TTL and 5 max keys
	cache := expirable.NewLRU[string, string](5, nil, time.Millisecond*10)


	// set value under key1.
	cache.Add("key1", "val1")

	// get value under key1
	r, ok := cache.Get("key1")

	// check for OK value
	if ok {
		fmt.Printf("value before expiration is found: %v, value: %q\n", ok, r)
	}

	// wait for cache to expire
	time.Sleep(time.Millisecond * 12)

	// get value under key1 after key expiration
	r, ok = cache.Get("key1")
	fmt.Printf("value after expiration is found: %v, value: %q\n", ok, r)

	// set value under key2, would evict old entry because it is already expired.
	cache.Add("key2", "val2")

	fmt.Printf("Cache len: %d\n", cache.Len())
	// Output:
	// value before expiration is found: true, value: "val1"
	// value after expiration is found: false, value: ""
	// Cache len: 1
}

最近版本更新:(数据更新于 2024-04-19 20:46:11)

2023-09-30 00:49:56 v2.0.7

2023-08-25 04:21:07 v2.0.6

2023-08-09 03:02:50 v2.0.5

2023-08-08 19:47:29 v1.0.2

2023-06-21 22:43:49 v2.0.4

2023-06-07 04:24:34 v2.0.3

2023-03-13 23:53:56 v2.0.2

2022-11-15 21:20:46 v1.0.1

2022-11-15 04:14:11 v2.0.0

2022-11-15 04:11:49 v0.6.0

hashicorp/golang-lru同语言 Go最近更新仓库

2024-04-29 16:39:16 SagerNet/sing-box

2024-04-28 12:22:52 apernet/hysteria

2024-04-27 17:19:55 flipped-aurora/gin-vue-admin

2024-04-27 16:58:31 hatchet-dev/hatchet

2024-04-27 01:48:29 daytonaio/daytona

2024-04-26 23:19:43 go-gost/gost