Kepler core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
919 B

package cache
import (
"errors"
"fmt"
"time"
"cygnux.net/kepler/config"
)
func SetupCache(cfg config.Config) (Cache, error) {
switch cfg.GetString("driver") {
case "redis":
return new_redis_cache(
cfg.GetString("host", "redis"),
cfg.GetUInt16("port", 6379),
cfg.GetInt64("db", 0),
cfg.GetString("password"),
cfg.GetBool("enabled", true))
case "sentinel":
return new_sentinel_cache(
cfg.GetString("host", "sentinel"),
cfg.GetUInt16("port", 6379),
cfg.GetString("master", "redis"),
cfg.GetInt64("db", 0),
cfg.GetString("password"),
cfg.GetBool("enabled", true))
case "mem":
return new_mem_cache(cfg.GetString("max", "32mb"))
default:
return nil, errors.New("Unsupported driver type: " + cfg.GetString("driver"))
}
return nil, nil
}
func log_timing(t1 time.Time, msg string, params ...interface{}) {
t2 := time.Now()
fmt.Println(t1, t2, t2.Sub(t1), msg, params)
}