add post-flush reheat action
This commit is contained in:
+11
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@@ -101,10 +102,19 @@ func main() {
|
||||
Admins: opts.Admins,
|
||||
DevMode: opts.DevMode,
|
||||
Exporter: &exporter,
|
||||
Cache: common.NewLoadingCache(4*time.Hour, 15*time.Minute),
|
||||
AuthProviders: makeAuthProviders(sessionStore),
|
||||
}
|
||||
|
||||
srv.Cache = common.NewLoadingCache(4*time.Hour, 15*time.Minute, func() {
|
||||
// set post-flush callback
|
||||
resp, err := http.Get(opts.RemarkURL + "/api/v1/list")
|
||||
if err != nil {
|
||||
log.Printf("[WARN] failed to refresh cached list, %s", err)
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
})
|
||||
|
||||
if opts.DevMode {
|
||||
log.Printf("[WARN] running in dev mode, no auth!")
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@ type LoadingCache interface {
|
||||
|
||||
// loadingCache implements LoadingCache interface on top of cache.Cache
|
||||
type loadingCache struct {
|
||||
bytesCache *cache.Cache
|
||||
bytesCache *cache.Cache
|
||||
postFlushFn func()
|
||||
}
|
||||
|
||||
// NewLoadingCache makes loadingCache implementation
|
||||
func NewLoadingCache(defaultExpiration, cleanupInterval time.Duration) LoadingCache {
|
||||
return &loadingCache{bytesCache: cache.New(defaultExpiration, cleanupInterval)}
|
||||
func NewLoadingCache(defaultExpiration, cleanupInterval time.Duration, postFlushFn func()) LoadingCache {
|
||||
return &loadingCache{bytesCache: cache.New(defaultExpiration, cleanupInterval), postFlushFn: postFlushFn}
|
||||
}
|
||||
|
||||
func (lc *loadingCache) Get(key string, ttl time.Duration, fn func() ([]byte, error)) (data []byte, err error) {
|
||||
@@ -39,4 +40,7 @@ func (lc *loadingCache) Get(key string, ttl time.Duration, fn func() ([]byte, er
|
||||
|
||||
func (lc *loadingCache) Flush() {
|
||||
lc.bytesCache.Flush()
|
||||
if lc.postFlushFn != nil {
|
||||
lc.postFlushFn()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user