Merge pull request #79 from alimy/pr-cache

optimize #78 change CacheIndex in conf.yaml to SimpleCacheIndex
pull/80/head
Michael Li 3 years ago committed by GitHub
commit 315060233b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ Features:
Develop: ["Base", "Option", "Sms", "AliOSS", "LoggerZinc"] Develop: ["Base", "Option", "Sms", "AliOSS", "LoggerZinc"]
Slim: ["Base", "LocalOSS", "LoggerFile"] Slim: ["Base", "LocalOSS", "LoggerFile"]
Base: ["Zinc", "MySQL", "Redis", "Alipay",] Base: ["Zinc", "MySQL", "Redis", "Alipay",]
Option: ["CacheIndex"] Option: ["SimpleCacheIndex"]
Sms: "SmsJuhe" Sms: "SmsJuhe"
SmsJuhe: SmsJuhe:
Key: Key:
@ -25,7 +25,7 @@ SmsJuhe:
Alipay: Alipay:
AppID: AppID:
PrivateKey: PrivateKey:
CacheIndex: # 缓存泡泡广场消息流 SimpleCacheIndex: # 缓存泡泡广场消息流
MaxIndexSize: 200 # 最大缓存条数 MaxIndexSize: 200 # 最大缓存条数
CheckTickDuration: 60 # 循环自检查每多少秒一次 CheckTickDuration: 60 # 循环自检查每多少秒一次
ExpireTickDuration: 300 # 每多少秒后强制过期缓存 ExpireTickDuration: 300 # 每多少秒后强制过期缓存

@ -15,7 +15,7 @@ var (
ServerSetting *ServerSettingS ServerSetting *ServerSettingS
AppSetting *AppSettingS AppSetting *AppSettingS
CacheIndexSetting *CacheIndexSettingS SimpleCacheIndexSetting *SimpleCacheIndexSettingS
SmsJuheSetting *SmsJuheSettings SmsJuheSetting *SmsJuheSettings
AlipaySetting *AlipaySettingS AlipaySetting *AlipaySettingS
ZincSetting *ZincSettingS ZincSetting *ZincSettingS
@ -43,7 +43,7 @@ func setupSetting(suite []string, noDefault bool) error {
objects := map[string]interface{}{ objects := map[string]interface{}{
"App": &AppSetting, "App": &AppSetting,
"Server": &ServerSetting, "Server": &ServerSetting,
"CacheIndex": &CacheIndexSetting, "SimpleCacheIndex": &SimpleCacheIndexSetting,
"Alipay": &AlipaySetting, "Alipay": &AlipaySetting,
"SmsJuhe": &SmsJuheSetting, "SmsJuhe": &SmsJuheSetting,
"LoggerFile": &loggerFileSetting, "LoggerFile": &loggerFileSetting,

@ -46,7 +46,7 @@ type AppSettingS struct {
TronApiKeys []string TronApiKeys []string
} }
type CacheIndexSettingS struct { type SimpleCacheIndexSettingS struct {
MaxIndexSize int MaxIndexSize int
CheckTickDuration int CheckTickDuration int
ExpireTickDuration int ExpireTickDuration int

@ -10,7 +10,7 @@ import (
) )
func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.PostFormated, error)) *simpleCacheIndexServant { func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.PostFormated, error)) *simpleCacheIndexServant {
s := conf.CacheIndexSetting s := conf.SimpleCacheIndexSetting
cacheIndex := &simpleCacheIndexServant{ cacheIndex := &simpleCacheIndexServant{
getIndexPosts: getIndexPosts, getIndexPosts: getIndexPosts,
maxIndexSize: s.MaxIndexSize, maxIndexSize: s.MaxIndexSize,

@ -71,11 +71,11 @@ func NewDataService(engine *gorm.DB, zinc *zinc.ZincClient) core.DataService {
} }
// initialize CacheIndex if needed // initialize CacheIndex if needed
if !conf.CfgIf("CacheIndex") { if conf.CfgIf("SimpleCacheIndex") {
ds.useCacheIndex = false
} else {
ds.useCacheIndex = true ds.useCacheIndex = true
ds.cacheIndex = newSimpleCacheIndexServant(ds.getIndexPosts) ds.cacheIndex = newSimpleCacheIndexServant(ds.getIndexPosts)
} else {
ds.useCacheIndex = false
} }
return ds return ds

Loading…
Cancel
Save