A light, high performance LRU cache package for Go, based on Concurrent-Map. This package have features as followed:
- nearly LRU cache algorithm
- use generic design,no need to serialize the struct or assert the type of interface.
Import the package:
import (
"github.com/lawyzheng/golru"
)
go get "github.com/lawyzheng/golru"
// Create a new map.
c := golru.New[string](0)
// Sets item within map, sets "bar" under key "foo"
c.Set("foo", "bar")
// Retrieve item from map.
bar, ok := c.Get("foo")
// Removes item under key "foo"
c.Remove("foo")
For more examples have a look at lru_test.go.
Running tests:
go test "github.com/lawyzheng/golru"
Contributions are highly welcome. In order for a contribution to be merged, please follow these guidelines:
- Open an issue and describe what you are after (fixing a bug, adding an enhancement, etc.).
- According to the core team's feedback on the above mentioned issue, submit a pull request, describing the changes and linking to the issue.
- New code must have test coverage.
- If the code is about performance issues, you must include benchmarks in the process (either in the issue or in the PR).
- In general, we would like to keep
golru
as simple as possible. Please keep this in mind when opening issues.
Thanks for orcaman/concurrent-map to offer the basic idea.
MIT (see LICENSE file)