diff --git a/config.yaml.sample b/config.yaml.sample index 7579428b..65b65eba 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -28,7 +28,7 @@ Alipay: SimpleCacheIndex: # 缓存泡泡广场消息流 MaxIndexSize: 200 # 最大缓存条数 CheckTickDuration: 60 # 循环自检查每多少秒一次 - ExpireTickDuration: 300 # 每多少秒后强制过期缓存 + ExpireTickDuration: 300 # 每多少秒后强制过期缓存, 设置为0禁止强制使缓存过期 LoggerFile: # 使用File写日志 SavePath: data/paopao-ce/logs FileName: app diff --git a/internal/dao/cache_index.go b/internal/dao/cache_index.go index 7d8d01ce..435b5d68 100644 --- a/internal/dao/cache_index.go +++ b/internal/dao/cache_index.go @@ -15,9 +15,16 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model. getIndexPosts: getIndexPosts, maxIndexSize: s.MaxIndexSize, indexPosts: make([]*model.PostFormated, 0), - indexActionCh: make(chan core.IndexActionT, 100), // optimize: size need configure by custom - checkTick: time.NewTicker(time.Duration(s.CheckTickDuration) * time.Second), // check whether need update index every 1 minute - expireIndexTick: time.NewTicker(time.Duration(s.ExpireTickDuration) * time.Second), // force expire index every 5 minute + indexActionCh: make(chan core.IndexActionT, 100), // optimize: size need configure by custom + checkTick: time.NewTicker(time.Duration(s.CheckTickDuration) * time.Second), // check whether need update index every 1 minute + expireIndexTick: time.NewTicker(time.Second), + } + + // force expire index every ExpireTickDuration second + if s.ExpireTickDuration != 0 { + cacheIndex.expireIndexTick.Reset(time.Duration(s.CheckTickDuration) * time.Second) + } else { + cacheIndex.expireIndexTick.Stop() } // start index posts