Skip to content

go-warmcache is a thin go package which manages an in-memory warm cache. It provides thread safety

Notifications You must be signed in to change notification settings

yoheimuta/go-warmcache

Repository files navigation

go-warmcache GoDoc Build Status CircleCI

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.

// 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()

About

go-warmcache is a thin go package which manages an in-memory warm cache. It provides thread safety

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published