Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/dboslee/lru
- Owner: dboslee
- License: mit
- Created: 2022-01-09T23:13:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-06T22:13:04.000Z (over 2 years ago)
- Last Synced: 2024-10-01T17:07:02.787Z (3 months ago)
- Topics: generics, go, golang, lru, lru-cache
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 119
- Watchers: 6
- 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))
...
}
```