https://github.com/hslam/lru
Package lru implements an LRU cache.
https://github.com/hslam/lru
cache go golang lru
Last synced: about 1 year ago
JSON representation
Package lru implements an LRU cache.
- Host: GitHub
- URL: https://github.com/hslam/lru
- Owner: hslam
- License: mit
- Created: 2021-02-03T08:56:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-12-28T15:15:11.000Z (over 4 years ago)
- Last Synced: 2023-07-27T18:04:44.519Z (almost 3 years ago)
- Topics: cache, go, golang, lru
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lru
[](https://pkg.go.dev/github.com/hslam/lru)
[](https://github.com/hslam/lru/actions)
[](https://codecov.io/gh/hslam/lru)
[](https://goreportcard.com/report/github.com/hslam/lru)
[](https://github.com/hslam/lru/blob/master/LICENSE)
Package lru implements an LRU cache.
## Get started
### Install
```
go get github.com/hslam/lru
```
### Import
```
import "github.com/hslam/lru"
```
### Usage
#### Example
```go
package main
import (
"fmt"
"github.com/hslam/lru"
)
func main() {
var capacity = 1024
var free lru.Free = func(key, value interface{}) {}
l := lru.New(capacity, free)
key := 1
value := "Hello world"
cost := len(value)
r := l.Set(key, value, cost)
r.Done()
if v, r, ok := l.Get(key); ok {
fmt.Println(v)
r.Done()
}
l.Remove(key)
l.Reset()
}
```
### Output
```
Hello world
```
### License
This package is licensed under a MIT license (Copyright (c) 2021 Meng Huang)
### Author
lru was written by Meng Huang.