Skip to content

dboslee/lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRU Cache

A simple LRU cache using go generics.

Examples

Basic usage.

func main() {
    cache := lru.New[string, string]()
    cache.Set("key", "value")
    value, _ := cache.Get("key")
    fmt.Println(value)
}

Set the capacity using the lru.WithCapacity option. The default capacity is set to 10000.

func main() {
    cache := lru.New[string, string](lru.WithCapacity(100))
    ...
}

A thread safe implementation is included for convenience.

func main() {
    cache := lru.NewSync[string, string](lru.WithCapacity(100))
    ...
}

Packages

No packages published

Languages