重构优化

This commit is contained in:
gotoeasy 2022-07-03 09:56:24 +08:00
parent 538c163e57
commit 24476f38b0
3 changed files with 12 additions and 12 deletions

View File

@ -80,19 +80,19 @@ func NewDocIndexStorage(storeName string, word string) *DocIndexStorage { // 存
mapStorage[cacheName] = store // 缓存起来
// 逐秒判断,若闲置超时则自动关闭
go autoCloseWhenMaxIdle(store)
go store.autoCloseWhenMaxIdle()
log.Println("打开DocIndexStorage", cacheName)
return store
}
func autoCloseWhenMaxIdle(store *DocIndexStorage) {
func (s *DocIndexStorage) autoCloseWhenMaxIdle() {
if conf.GetMaxIdleTime() > 0 {
ticker := time.NewTicker(time.Second)
for {
<-ticker.C
if time.Now().Unix()-store.lastTime > int64(conf.GetMaxIdleTime()) {
store.Close()
if time.Now().Unix()-s.lastTime > int64(conf.GetMaxIdleTime()) {
s.Close()
ticker.Stop()
break
}

View File

@ -83,19 +83,19 @@ func NewWordIndexStorage(storeName string, word string) *WordIndexStorage { //
mapStorage[cacheName] = store // 缓存起来
// 逐秒判断,若闲置超时则自动关闭
go autoCloseWhenMaxIdle(store)
go store.autoCloseWhenMaxIdle()
log.Println("打开WordIndexStorage", cacheName)
return store
}
func autoCloseWhenMaxIdle(store *WordIndexStorage) {
func (s *WordIndexStorage) autoCloseWhenMaxIdle() {
if conf.GetMaxIdleTime() > 0 {
ticker := time.NewTicker(time.Second)
for {
<-ticker.C
if time.Now().Unix()-store.lastTime > int64(conf.GetMaxIdleTime()) {
store.Close()
if time.Now().Unix()-s.lastTime > int64(conf.GetMaxIdleTime()) {
s.Close()
ticker.Stop()
break
}

View File

@ -66,19 +66,19 @@ func GetSysmntStorage(storeName string) *SysmntStorage { // 存储器,文档
sysmntStorage = store // 缓存起来
// 逐秒判断,若闲置超时则自动关闭
go autoCloseWhenMaxIdle(store)
go store.autoCloseWhenMaxIdle()
log.Println("打开SysmntStorage", cacheName)
return store
}
func autoCloseWhenMaxIdle(store *SysmntStorage) {
func (s *SysmntStorage) autoCloseWhenMaxIdle() {
if conf.GetMaxIdleTime() > 0 {
ticker := time.NewTicker(time.Second)
for {
<-ticker.C
if time.Now().Unix()-store.lastTime > int64(conf.GetMaxIdleTime()) {
store.Close()
if time.Now().Unix()-s.lastTime > int64(conf.GetMaxIdleTime()) {
s.Close()
ticker.Stop()
break
}