Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat: change default cache dir to data, create dir if not exist.

LinkinStar1cd83f4e879d
diff --git a/configs/config.yaml b/configs/config.yaml
index 3e7cfd84..0ec1a601 100644
--- a/configs/config.yaml
+++ b/configs/config.yaml
@@ -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:
diff --git a/internal/base/data/data.go b/internal/base/data/data.go
index cb50f7e0..b6878181 100644
--- a/internal/base/data/data.go
+++ b/internal/base/data/data.go
@@ -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)