fix:修复旧版本没有标识文档读写缓存失败的BUG

pull/358/head
lifei6671 2018-08-13 15:04:52 +08:00
parent b50d39f690
commit c7251697b3
7 changed files with 60 additions and 44 deletions

View File

@ -84,6 +84,9 @@ WORKDIR /mindoc
COPY --from=0 /go/src/github.com/lifei6671/mindoc .
# 时区设置
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
RUN chmod +x start.sh

5
cache/cache.go vendored
View File

@ -9,6 +9,7 @@ import (
"github.com/astaxie/beego"
)
var bm cache.Cache
func Get(key string, e interface{}) error {
@ -45,9 +46,6 @@ func Get(key string,e interface{}) error {
return errors.New("value is not []byte or string")
}
func GetMulti(keys []string) []interface{} {
return bm.GetMulti(keys)
}
func Put(key string, val interface{}, timeout time.Duration) error {
@ -83,6 +81,7 @@ func ClearAll() error{
func StartAndGC(config string) error {
return bm.StartAndGC(config)
}
//初始化缓存
func Init(c cache.Cache) {
bm = c

View File

@ -108,8 +108,13 @@ func RegisterLogger(log string) {
logs.Async(1e3)
}
if log == "" {
logPath,err := filepath.Abs(beego.AppConfig.DefaultString("log_path",conf.WorkingDir("runtime","logs")))
if err == nil {
log = logPath
}else{
log = conf.WorkingDir("runtime","logs")
}
}
logPath := filepath.Join(log, "log.log")
@ -235,9 +240,7 @@ func ResolveCommand(args []string) {
conf.WorkingDirectory = filepath.Dir(p)
}
}
if conf.LogFile == "" {
conf.LogFile = conf.WorkingDir("runtime","logs")
}
if conf.ConfigurationFile == "" {
conf.ConfigurationFile = conf.WorkingDir( "conf", "app.conf")
config := conf.WorkingDir("conf", "app.conf.example")
@ -252,6 +255,15 @@ func ResolveCommand(args []string) {
if err := beego.LoadAppConfig("ini", conf.ConfigurationFile);err != nil {
log.Fatal("An error occurred:", err)
}
if conf.LogFile == "" {
logPath,err := filepath.Abs(beego.AppConfig.DefaultString("log_path",conf.WorkingDir("runtime","logs")))
if err == nil {
conf.LogFile = logPath
}else{
conf.LogFile = conf.WorkingDir("runtime","logs")
}
}
conf.AutoLoadDelay = beego.AppConfig.DefaultInt("config_auto_delay",0)
uploads := conf.WorkingDir("uploads")
@ -282,6 +294,7 @@ func RegisterCache() {
isOpenCache := beego.AppConfig.DefaultBool("cache", false)
if !isOpenCache {
cache.Init(&cache.NullCache{})
return
}
beego.Info("正常初始化缓存配置.")
cacheProvider := beego.AppConfig.String("cache_provider")
@ -355,13 +368,13 @@ func RegisterCache() {
bc, err := json.Marshal(&memcacheConfig)
if err != nil {
beego.Error("初始化Redis缓存失败:", err)
beego.Error("初始化 Redis 缓存失败 ->", err)
os.Exit(1)
}
memcache, err := beegoCache.NewCache("memcache", string(bc))
if err != nil {
beego.Error("初始化Memcache缓存失败:", err)
beego.Error("初始化 Memcache 缓存失败 ->", err)
os.Exit(1)
}
@ -397,10 +410,13 @@ func RegisterAutoLoadConfig() {
}
if modTime != f.ModTime() {
if err := beego.LoadAppConfig("ini", conf.ConfigurationFile); err != nil {
beego.Error("An error occurred:", err)
beego.Error("An error occurred ->", err)
break
}
modTime = f.ModTime()
RegisterCache()
RegisterLogger("")
beego.Info("配置文件已加载")
}
}

View File

@ -179,9 +179,7 @@ func (m *Document) RemoveCache() {
//从缓存获取
func (m *Document) FromCacheById(id int) (*Document, error) {
var doc Document
if err := cache.Get("Document.Id."+strconv.Itoa(id), &m); err == nil && m.DocumentId > 0 {
m = &doc
beego.Info("从缓存中获取文档信息成功 ->", m.DocumentId)
return m, nil
}

View File

@ -5,8 +5,6 @@ cd /mindoc/
if [ ! -f "/mindoc/conf/app.conf" ] ; then
cp /mindoc/conf/app.conf.example /mindoc/conf/app.conf
sed -i "s#^db_adapter=.*#db_adapter=sqlite3#g" conf/app.conf
sed -i "s#^db_database.*#db_database=./database/mindoc.db#g" conf/app.conf
fi

View File

@ -1,11 +1,13 @@
<div class="footer">
<div class="container">
<div class="row text-center border-top">
<span><a href="https://www.iminho.me" target="_blank">MinDoc</a></span>
<span><a href="https://www.iminho.me" target="_blank">官方网站</a></span>
<span>&nbsp;·&nbsp;</span>
<span><a href="https://github.com/lifei6671/mindoc/issues" target="_blank">意见反馈</a></span>
<span>&nbsp;·&nbsp;</span>
<span><a href="https://github.com/lifei6671/mindoc" target="_blank">Github</a></span>
<span><a href="https://github.com/lifei6671/mindoc" target="_blank">项目源码</a></span>
<span>&nbsp;·&nbsp;</span>
<span><a href="https://www.iminho.me/wiki/docs/mindoc/" target="_blank">使用手册</a></span>
</div>
{{if ne .site_beian ""}}
<div class="row text-center">