optimize #78 change CacheIndex configure in conf.yaml to SimpleCacheIndex

pull/79/head
alimy 2 years ago
parent 3c3071791e
commit f24252d6ab

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

@ -13,18 +13,18 @@ var (
redisSetting *RedisSettingS
features *FeaturesSettingS
ServerSetting *ServerSettingS
AppSetting *AppSettingS
CacheIndexSetting *CacheIndexSettingS
SmsJuheSetting *SmsJuheSettings
AlipaySetting *AlipaySettingS
ZincSetting *ZincSettingS
AliOSSSetting *AliOSSSettingS
MinIOSetting *MinIOSettingS
S3Setting *S3SettingS
LocalOSSSetting *LocalOSSSettingS
JWTSetting *JWTSettingS
Mutex *sync.Mutex
ServerSetting *ServerSettingS
AppSetting *AppSettingS
SimpleCacheIndexSetting *SimpleCacheIndexSettingS
SmsJuheSetting *SmsJuheSettings
AlipaySetting *AlipaySettingS
ZincSetting *ZincSettingS
AliOSSSetting *AliOSSSettingS
MinIOSetting *MinIOSettingS
S3Setting *S3SettingS
LocalOSSSetting *LocalOSSSettingS
JWTSetting *JWTSettingS
Mutex *sync.Mutex
)
func setupSetting(suite []string, noDefault bool) error {
@ -41,21 +41,21 @@ func setupSetting(suite []string, noDefault bool) error {
}
objects := map[string]interface{}{
"App": &AppSetting,
"Server": &ServerSetting,
"CacheIndex": &CacheIndexSetting,
"Alipay": &AlipaySetting,
"SmsJuhe": &SmsJuheSetting,
"LoggerFile": &loggerFileSetting,
"LoggerZinc": &loggerZincSetting,
"MySQL": &mySQLSetting,
"Zinc": &ZincSetting,
"Redis": &redisSetting,
"JWT": &JWTSetting,
"AliOSS": &AliOSSSetting,
"MinIO": &MinIOSetting,
"LocalOSS": &LocalOSSSetting,
"S3": &S3Setting,
"App": &AppSetting,
"Server": &ServerSetting,
"SimpleCacheIndex": &SimpleCacheIndexSetting,
"Alipay": &AlipaySetting,
"SmsJuhe": &SmsJuheSetting,
"LoggerFile": &loggerFileSetting,
"LoggerZinc": &loggerZincSetting,
"MySQL": &mySQLSetting,
"Zinc": &ZincSetting,
"Redis": &redisSetting,
"JWT": &JWTSetting,
"AliOSS": &AliOSSSetting,
"MinIO": &MinIOSetting,
"LocalOSS": &LocalOSSSetting,
"S3": &S3Setting,
}
if err = setting.Unmarshal(objects); err != nil {
return err

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

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

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

Loading…
Cancel
Save