mirror of https://gitee.com/answerdev/answer.git
feat: change default cache dir to data, create dir if not exist.
This commit is contained in:
parent
10a06573d5
commit
1cd83f4e87
|
@ -6,7 +6,7 @@ data:
|
|||
driver: "mysql"
|
||||
connection: root:root@tcp(db:3306)/answer
|
||||
cache:
|
||||
file_path: "/tmp/cache/cache.db"
|
||||
file_path: "/data/cache/cache.db"
|
||||
i18n:
|
||||
bundle_dir: "/data/i18n"
|
||||
swaggerui:
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/answerdev/answer/pkg/dir"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
@ -69,6 +71,12 @@ func NewCache(c *CacheConf) (cache.Cache, func(), error) {
|
|||
memCache := memory.NewCache()
|
||||
|
||||
if len(c.FilePath) > 0 {
|
||||
cacheFileDir := filepath.Dir(c.FilePath)
|
||||
log.Debugf("try to create cache directory %s", cacheFileDir)
|
||||
err := dir.CreateDirIfNotExist(cacheFileDir)
|
||||
if err != nil {
|
||||
log.Errorf("create cache dir failed: %s", err)
|
||||
}
|
||||
log.Infof("try to load cache file from %s", c.FilePath)
|
||||
if err := memory.Load(memCache, c.FilePath); err != nil {
|
||||
log.Warn(err)
|
||||
|
|
Loading…
Reference in New Issue