https://github.com/Arianxx/gorsy-cache
A concurrency-safe in-memory k/v cache store implemented by Golang that supports the lru, lfu, arc algorithm etc.
https://github.com/Arianxx/gorsy-cache
cache go lru
Last synced: 5 months ago
JSON representation
A concurrency-safe in-memory k/v cache store implemented by Golang that supports the lru, lfu, arc algorithm etc.
- Host: GitHub
- URL: https://github.com/Arianxx/gorsy-cache
- Owner: Arianxx
- License: mit
- Created: 2019-03-27T11:12:40.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-01T08:57:56.000Z (almost 6 years ago)
- Last Synced: 2024-08-03T23:15:27.713Z (9 months ago)
- Topics: cache, go, lru
- Language: Go
- Size: 17.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - gorsy-cache - safe in-memory k/v cache store implemented by Golang that supports the lru, lfu, arc algorithm etc. (Repositories)
README
```
__
____ _____ ____________ __ _________ ______/ /_ ___
/ __ `/ __ \/ ___/ ___/ / / /_____/ ___/ __ `/ ___/ __ \/ _ \
/ /_/ / /_/ / / (__ ) /_/ /_____/ /__/ /_/ / /__/ / / / __/
\__, /\____/_/ /____/\__, / \___/\__,_/\___/_/ /_/\___/
/____/ /____/
```Gorsy is a concurrency-safe in-memory k/v cache store implemented by Golang that supports the lru, lfu, arc algorithm etc.
### Example
```golang
package mainimport (
"fmt"
"github.com/arianxx/gorsy-cache"
)func loader(_ interface{}) (interface{}, error) {
return "baka!", nil
}func beforeEvict(key, value interface{}) {
fmt.Printf("%v: %v was be removed\n", key, value)
}func main() {
builder, err := gorsy_cache.NewBuilder(gorsy_cache.LFU, 10)
if err != nil {
panic("build cache error: " + err.Error())
}
cache := builder.
SetName("rocket").
SetDefaultExpiration(gorsy_cache.DefaultExpiration).
SetLoaderFunc(loader).
SetBeforeEvictedFunc(beforeEvict).
Build()
cache.Set(1, 2)
cache.Set(2, 3)
fmt.Println(cache.Get(1))
fmt.Println(cache.Get(2))
fmt.Println(cache.GetOnlyPresent(3))
cache.Remove(1)
fmt.Println(cache.Get(1))
}```