mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
重构优化
This commit is contained in:
parent
538c163e57
commit
24476f38b0
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user