added options to configure cache
This commit is contained in:
parent
23dc9f777e
commit
416745ddab
6 changed files with 70 additions and 4 deletions
|
@ -206,7 +206,7 @@ Teams sind global, d.h. Ein Team kann mehrere Namespaces verwalten.
|
||||||
|
|
||||||
### Short Term
|
### Short Term
|
||||||
|
|
||||||
* [ ] Cacher konfigurierbar
|
* [x] Cacher konfigurierbar
|
||||||
* [ ] Validation der ankommenden structs, am besten mit https://github.com/go-validator/validator
|
* [ ] Validation der ankommenden structs, am besten mit https://github.com/go-validator/validator
|
||||||
* [ ] Wenn die ID bei irgendeiner GetByID... Methode < 1 ist soll ein error not exist geworfen werden
|
* [ ] Wenn die ID bei irgendeiner GetByID... Methode < 1 ist soll ein error not exist geworfen werden
|
||||||
|
|
||||||
|
|
20
Gopkg.lock
generated
20
Gopkg.lock
generated
|
@ -24,6 +24,17 @@
|
||||||
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
|
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
|
||||||
version = "v1.4.7"
|
version = "v1.4.7"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:0594af97b2f4cec6554086eeace6597e20a4b69466eb4ada25adf9f4300dddd2"
|
||||||
|
name = "github.com/garyburd/redigo"
|
||||||
|
packages = [
|
||||||
|
"internal",
|
||||||
|
"redis",
|
||||||
|
]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "a69d19351219b6dd56f274f96d85a7014a2ec34e"
|
||||||
|
version = "v1.6.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:d2b67246c3fa959edfa1be84b407cf0a0a4cabbace0843814b1729b5af808d9e"
|
digest = "1:d2b67246c3fa959edfa1be84b407cf0a0a4cabbace0843814b1729b5af808d9e"
|
||||||
name = "github.com/go-sql-driver/mysql"
|
name = "github.com/go-sql-driver/mysql"
|
||||||
|
@ -53,6 +64,14 @@
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "29d4a0330a00b9be468b70e3fb0f74109348c358"
|
revision = "29d4a0330a00b9be468b70e3fb0f74109348c358"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:d4a957ebe4ccebc299c1f6b6a78a0713af379721980cf14990b8ab8fa93cd92d"
|
||||||
|
name = "github.com/go-xorm/xorm-redis-cache"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "859b313566b2ef090319245fd4fe7692f25dbd79"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10"
|
digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10"
|
||||||
name = "github.com/hashicorp/hcl"
|
name = "github.com/hashicorp/hcl"
|
||||||
|
@ -282,6 +301,7 @@
|
||||||
"github.com/go-sql-driver/mysql",
|
"github.com/go-sql-driver/mysql",
|
||||||
"github.com/go-xorm/core",
|
"github.com/go-xorm/core",
|
||||||
"github.com/go-xorm/xorm",
|
"github.com/go-xorm/xorm",
|
||||||
|
"github.com/go-xorm/xorm-redis-cache",
|
||||||
"github.com/imdario/mergo",
|
"github.com/imdario/mergo",
|
||||||
"github.com/labstack/echo",
|
"github.com/labstack/echo",
|
||||||
"github.com/labstack/echo/middleware",
|
"github.com/labstack/echo/middleware",
|
||||||
|
|
|
@ -20,4 +20,16 @@ database:
|
||||||
# When using sqlite, this is the path where to store the data
|
# When using sqlite, this is the path where to store the data
|
||||||
Path: "./vikunja.db"
|
Path: "./vikunja.db"
|
||||||
# Whether to show mysql queries or not. Useful for debugging.
|
# Whether to show mysql queries or not. Useful for debugging.
|
||||||
showqueries: "false"
|
showqueries: "false"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
# If cache is enabled or not
|
||||||
|
enabled: false
|
||||||
|
# Cache type. Possible values are memory or redis
|
||||||
|
type: memory
|
||||||
|
# When using memory this defines the maximum size an element can take
|
||||||
|
maxelementsize: 1000
|
||||||
|
# When using redis, this is the host of the redis server including its port.
|
||||||
|
redishost: 'localhost:6379'
|
||||||
|
# When using redis, this is the password used to authenicate against the redis server
|
||||||
|
redispassword: ''
|
||||||
|
|
|
@ -45,4 +45,16 @@ database:
|
||||||
Path: "./vikunja.db"
|
Path: "./vikunja.db"
|
||||||
# Whether to show mysql queries or not. Useful for debugging.
|
# Whether to show mysql queries or not. Useful for debugging.
|
||||||
showqueries: "false"
|
showqueries: "false"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
# If cache is enabled or not
|
||||||
|
enabled: false
|
||||||
|
# Cache type. Possible values are memory or redis
|
||||||
|
type: memory
|
||||||
|
# When using memory this defines the maximum size an element can take
|
||||||
|
maxelementsize: 1000
|
||||||
|
# When using redis, this is the host of the redis server including its port.
|
||||||
|
redishost: 'localhost:6379'
|
||||||
|
# When using redis, this is the password used to authenicate against the redis server
|
||||||
|
redispassword: ''
|
||||||
```
|
```
|
||||||
|
|
|
@ -27,6 +27,12 @@ func InitConfig() (err error) {
|
||||||
viper.SetDefault("database.database", "vikunja")
|
viper.SetDefault("database.database", "vikunja")
|
||||||
viper.SetDefault("database.path", "./vikunja.db")
|
viper.SetDefault("database.path", "./vikunja.db")
|
||||||
viper.SetDefault("database.showqueries", false)
|
viper.SetDefault("database.showqueries", false)
|
||||||
|
// Cacher
|
||||||
|
viper.SetDefault("cache.enabled", false)
|
||||||
|
viper.SetDefault("cache.type", "memory")
|
||||||
|
viper.SetDefault("cache.maxelementsize", 1000)
|
||||||
|
viper.SetDefault("cache.redishost", "localhost:6379")
|
||||||
|
viper.SetDefault("cache.redispassword", "")
|
||||||
|
|
||||||
// Init checking for environment variables
|
// Init checking for environment variables
|
||||||
viper.SetEnvPrefix("vikunja")
|
viper.SetEnvPrefix("vikunja")
|
||||||
|
|
|
@ -6,7 +6,10 @@ import (
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
_ "github.com/mattn/go-sqlite3" // Because.
|
_ "github.com/mattn/go-sqlite3" // Because.
|
||||||
|
xrc "github.com/go-xorm/xorm-redis-cache"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"encoding/gob"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -58,8 +61,21 @@ func SetEngine() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
//cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
|
if viper.GetBool("cache.enabled") {
|
||||||
//x.SetDefaultCacher(cacher)
|
switch viper.GetString("cache.type") {
|
||||||
|
case "memory":
|
||||||
|
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), viper.GetInt("cache.maxelementsize"))
|
||||||
|
x.SetDefaultCacher(cacher)
|
||||||
|
break
|
||||||
|
case "redis":
|
||||||
|
cacher := xrc.NewRedisCacher(viper.GetString("cache.redishost"), viper.GetString("cache.redispassword"), xrc.DEFAULT_EXPIRATION, x.Logger())
|
||||||
|
x.SetDefaultCacher(cacher)
|
||||||
|
gob.Register(tables)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
fmt.Println("Did not find a valid cache type. Caching disabled. Please refer to the docs for poosible cache types.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
x.SetMapper(core.GonicMapper{})
|
x.SetMapper(core.GonicMapper{})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue