lfu is a lightweight package that implements lfu cache algorithm in Go.
go get github.com/erfanmomeniii/lfu
Next, include it in your application:
import "github.com/erfanmomeniii/lfu"
The following example illustrates how to use this package
package main
import (
"fmt"
"github.com/erfanmomeniii/lru"
)
func main() {
l := lru.New(2)
// 2 is the size of lru (default 2000)
l.Set("a", 12)
l.Set("b", 13)
fmt.Println(l.Get("a"))
// 12
l.Set("c", "hi")
fmt.Println(l.Has("c"))
// false
}
Lfu is an instantiation of the lfu.
func New(size ...int64) *Lfu
New creates a new instance of a lfu.
func (l *Lfu) Set(key any, value any)
Set adds or updates with inputted key and value.
func (l *Lfu) Get(key any) any
Get returns the value associated with the inputted key.
func (l *Lfu) Has(key any) bool
Has checks whether the key exists or not.
Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.