Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/souravray/lru
Another LRU Cache implemented in GO
https://github.com/souravray/lru
Last synced: about 2 months ago
JSON representation
Another LRU Cache implemented in GO
- Host: GitHub
- URL: https://github.com/souravray/lru
- Owner: souravray
- License: mit
- Created: 2019-09-22T11:56:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-23T09:31:53.000Z (over 5 years ago)
- Last Synced: 2024-06-20T12:41:00.692Z (7 months ago)
- Language: Go
- Size: 24.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LRU
Another thread-safe LRU Cache implemented in GO.## Install
```
$ go get github.com/souravray/lru
```
## Sample Usage & Documentation```go
package mainimport (
"github.com/souravray/lru"
"fmt"
)func main() {
c, err := lru.New(20)
if err != nil {
panic(err)
}
c.Add("Key1", "ok")
value, ok := c.Fetch("Key1")
if !ok {
panic("Cannot fetch value for Key1")
}
fmt.Println("Key1:", value)
for i:=2; i<22; i++ {
c.Add(i, "ok")
}
if c.Exist("Key1") {
panic("Key1: Stale key")
} else {
fmt.Println("Key1: Evicted")
}
}
```
```
Key1: ok
Key1: Evicted
```Documentation is available on [Godoc](https://godoc.org/github.com/souravray/lru)
## Unit Test
Unit tests are avilable for list and base lru implementations. You can run unit test-cases by
```
$ go test -v -cover
```
Unit test code coverage is 70.2%, and thread safe methods doesn't have separate unit test-cases. You can also check the [test-coverage](http://raysourav.com/lru/cover.html) report.## Benchmarking
At best-case scinarions the LRU perfoms 180 ns/op (on avarage). You can run the benchmark tests by
```
go test -bench=. -benchtime=1s
```