Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dboslee/lru

LRU cache using go generics
https://github.com/dboslee/lru

generics go golang lru lru-cache

Last synced: 2 months ago
JSON representation

LRU cache using go generics

Awesome Lists containing this project

README

        

# LRU Cache
A simple LRU cache using go generics.

## Examples
Basic usage.
```go
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.
```go
func main() {
cache := lru.New[string, string](lru.WithCapacity(100))
...
}
```
A thread safe implementation is included for convenience.
```go
func main() {
cache := lru.NewSync[string, string](lru.WithCapacity(100))
...
}
```