Beispiel #1
0
// memcache:
// - host
// - port
func MemcacheFromConfig(container string) Cacher {
	host := conf.String(container+".host", "")
	panik.If(host == "", "memcache host not specified")

	port := conf.Int(container+".port", 0)
	panik.If(port == 0, "memcache port not specified")

	return NewMemcache(host, port)
}
Beispiel #2
0
// redis:
// - host
// - port
// - db
func RedisFromConfig(container string) Cacher {
	host := conf.String(container+".host", "")
	panik.If(host == "", "redis host not specified")

	port := conf.Int(container+".port", 0)
	panik.If(port == 0, "redis port not specified")

	db := conf.Int(container+".db", 0)

	return NewRedis(host, port, db)
}
Beispiel #3
0
func FromConfig(container string) (out Cacher) {

	cType := conf.String(container+".type", "")
	panik.If(cType == "", "cache type is not specified")

	switch cType {
	case "memcache":
		out = MemcacheFromConfig(container)

	case "redis":
		out = RedisFromConfig(container)

	case "inmem":
		out = InmemFromConfig(container)

	case "debug":
		out = DebugFromConfig(container)

	default:
		panic("unknown cache type specifed: " + cType)
	}

	return out
}