https://github.com/vardius/lru-cache
A Least Recently Used (LRU) Cache organizes items in order of use, allowing you to quickly identify which item hasn't been used for the longest amount of time.
https://github.com/vardius/lru-cache
Last synced: over 1 year ago
JSON representation
A Least Recently Used (LRU) Cache organizes items in order of use, allowing you to quickly identify which item hasn't been used for the longest amount of time.
- Host: GitHub
- URL: https://github.com/vardius/lru-cache
- Owner: vardius
- License: mit
- Created: 2019-09-22T06:53:01.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-16T13:28:31.000Z (almost 6 years ago)
- Last Synced: 2025-01-23T00:43:11.449Z (over 1 year ago)
- Language: Go
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
ποΈ lru-cache
================
[](https://travis-ci.org/vardius/lru-cache)
[](https://goreportcard.com/report/github.com/vardius/lru-cache)
[](https://codecov.io/gh/vardius/lru-cache)
[](https://pkg.go.dev/github.com/vardius/lru-cache)
[](https://github.com/vardius/lru-cache/blob/master/LICENSE.md)

Go simple LRU in memory cache
A Least Recently Used (LRU) Cache organizes items in order of use, allowing you to quickly identify which item hasn't been used for the longest amount of time.
* Strengths:
- Super fast accesses. LRU caches store items in order from most-recently used to least-recently used. That means both can be accessed in O(1)O(1) time.
- Super fast updates. Each time an item is accessed, updating the cache takes O(1) time.
π ABOUT
==================================================
Contributors:
* [RafaΕ Lorenz](http://rafallorenz.com)
Want to contribute ? Feel free to send pull requests!
Have problems, bugs, feature ideas?
We are using the github [issue tracker](https://github.com/vardius/lru-cache/issues) to manage them.
## π Documentation
For __examples__ **visit [godoc#pkg-examples](http://godoc.org/github.com/vardius/lru-cache#pkg-examples)**
For **GoDoc** reference, **visit [pkg.go.dev](https://pkg.go.dev/github.com/vardius/lru-cache)**
π HOW TO USE
==================================================
## π
Benchmark
**CPU: 3,3 GHz Intel Core i7**
**RAM: 16 GB 2133 MHz LPDDR3**
```bash
β lru-cache git:(master) go test -bench=. -cpu=4 -benchmem
goos: darwin
goarch: amd64
pkg: github.com/vardius/lru-cache
BenchmarkRead-4 23051137 50.1 ns/op 0 B/op 0 allocs/op
BenchmarkWrite-4 23097510 51.8 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/vardius/lru-cache 2.713s
```
## π« Basic example
```go
package main
import (
"fmt"
"log"
lrucache "github.com/vardius/lru-cache"
)
func main() {
c, err := lrucache.New("example-cache", 10*lrucache.MB)
if err != nil {
log.Fatal(err)
return
}
item, err := c.Get("test")
if err != nil {
log.Fatal(err)
return
}
if item == nil {
if err = c.Set("test", []byte("value")); err != nil {
log.Fatal(err)
return
}
}
got, err := c.Get("test")
if err != nil {
log.Fatal(err)
return
}
fmt.Println(string(got))
// Output:
// value
}
```
π [License](LICENSE.md)
-------
This package is released under the MIT license. See the complete license in the package