https://github.com/yoheimuta/go-warmcache
go-warmcache is a thin go package which manages an in-memory warm cache. It provides thread safety
https://github.com/yoheimuta/go-warmcache
autoreload cache go golang inmemory library warmcache warmup
Last synced: about 1 year ago
JSON representation
go-warmcache is a thin go package which manages an in-memory warm cache. It provides thread safety
- Host: GitHub
- URL: https://github.com/yoheimuta/go-warmcache
- Owner: yoheimuta
- Created: 2017-10-26T02:13:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-30T00:24:57.000Z (over 8 years ago)
- Last Synced: 2025-03-13T15:18:06.325Z (over 1 year ago)
- Topics: autoreload, cache, go, golang, inmemory, library, warmcache, warmup
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-warmcache [](https://godoc.org/github.com/yoheimuta/go-warmcache) [](https://travis-ci.org/yoheimuta/go-warmcache) [](https://circleci.com/gh/yoheimuta/go-warmcache/tree/master)
go-warmcache is a thin go package which manages an in-memory warm cache.
It provides thread safety.
You can use this package...
- To avoid delay of response time at first access
- To avoid thundering hurd
### Installation
```
go get github.com/yoheimuta/go-warmcache
```
### Usage
See example/main.go and example_test.go in detail.
```go
// create CacheMgr. call cacheFunc to create a warm cache in this method. refresh cache automatically every interval.
c, err := warmcache.NewCacheMgr(cacheFunc, interval, elapsedChan)
if err != nil {
log.Fatal("cacheFunc is failed", err)
}
// fetch cache. no origin access. always warm.
data, isStale, err := c.CacheData()
if isStale {
log.Fatal("cache data is stale. cacheFunc is slower than the interval")
}
if err != nil {
log.Fatal("cacheFunc is failed. cache data is also stale, not empty", err)
}
log.Println("cache data", data)
// after the interval...
// fetch new cache.
data, isStale, err = c.CacheData()
```