https://github.com/dboslee/lru
LRU cache using go generics
https://github.com/dboslee/lru
generics go golang lru lru-cache
Last synced: 6 months ago
JSON representation
LRU cache using go generics
- Host: GitHub
- URL: https://github.com/dboslee/lru
- Owner: dboslee
- License: mit
- Created: 2022-01-09T23:13:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-06T22:13:04.000Z (over 3 years ago)
- Last Synced: 2025-03-27T05:51:14.017Z (7 months ago)
- Topics: generics, go, golang, lru, lru-cache
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 119
- Watchers: 5
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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))
...
}
```