Categorygithub.com/floatdrop/2q
repositorypackage
0.1.1
Repository: https://github.com/floatdrop/2q.git
Documentation: pkg.go.dev

# README

2q

Go Reference CI Coverage Go Report Card

Thread safe GoLang 2Q cache.

Example

import (
	"fmt"

	twoqueue "github.com/floatdrop/2q"
)

func main() {
	cache := twoqueue.New[string, int](256)

	cache.Set("Hello", 5)

	if e := cache.Get("Hello"); e != nil {
		fmt.Println(*e)
		// Output: 5
	}
}

TTL

See LRU TTL example.

Benchmarks

floatdrop/twoqueue:
	Benchmark2Q_Rand-8   	 4296108	       274.9 ns/op	      33 B/op	       2 allocs/op
	Benchmark2Q_Freq-8   	 4674632	       253.8 ns/op	      31 B/op	       2 allocs/op

hashicorp/golang-lru:
	Benchmark2Q_Rand-8    	 2847627	       411.9 ns/op	     135 B/op	       5 allocs/op
	Benchmark2Q_Freq-8    	 3323764	       354.2 ns/op	     122 B/op	       5 allocs/op