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) }