From 77d8bdbc58d71f05e4a1fcc7124b97c869c7c3e3 Mon Sep 17 00:00:00 2001 From: alimy Date: Sat, 11 Jun 2022 11:41:21 +0800 Subject: [PATCH] optimize #78 support disable expire cache index if needed --- config.yaml.sample | 2 +- internal/dao/cache_index.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) 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